Asp.net c# mvc Training-Day-5 of Day-9

19
AHM Pervej Kabir Analyst Programmer [email protected] Cell:+8801757051005 Day-5: 18 October 2017 ASP.Net C#- MVC-5 Training

Transcript of Asp.net c# mvc Training-Day-5 of Day-9

AHM Pervej KabirAnalyst Programmer

[email protected]

Cell:+8801757051005 Day-5: 18 October 2017

ASP.Net C#- MVC-5 Training

Introduction

What is LINQ?

Why LINQ?

LINQ Query & Method Syntax

Anatomy of the Lambda Expression

Standard Query Operators:

Expression in LINQ

Expression Tree

Immediate Execution of LINQ Query

let & into keyword

Sample LINQ Queries

What Is LINQ

LINQ (Language Integrated Query) is uniform query syntax in C# and VB.NET used to save and retrieve data fromdifferent sources. It is integrated in C# or VB, thereby eliminating the mismatch between programming languages anddatabases, as well as providing a single querying interface for different types of data sources.

For example, SQL is a Structured Query Language used to save and retrieve data from a database. In the sameway, LINQ is a structured query syntax built in C# and VB.NET used to save and retrieve data from different typesof data sources like an Object Collection, SQL server database, XML, web service etc.

LINQ always works with objects so you can use the same basic coding patterns to query and transform data inXML documents, SQL databases, ADO.NET Datasets, .NET collections, and any other format for which a LINQprovider is available.

Why LINQ?

Familiar language: Developers don’t have to learn a new query language for each type ofdata source or data format.

Less coding: It reduces the amount of code to be written as compared with a moretraditional approach.

Readable code: LINQ makes the code more readable so other developers can easilyunderstand and maintain it.

Standardized way of querying multiple data sources: The same LINQ syntax can beused to query multiple data sources.

Compile time safety of queries: It provides type checking of objects at compile time.

IntelliSense Support: LINQ provides IntelliSense for generic collections.

Shaping data: You can retrieve data in different shapes.

LINQ Query Syntax:

Example:

Example:

LINQ Method Syntax:

C# 3.0(.NET 3.5) introduced the lambda expression along with LINQ.

Example:

Lamda Expression:

Standard Query Operators in query

Standard Query Operators in Method

Where Clause:

Where Extension Method:

Then By:

Group By:

Joining

Aggregate Function:

Concatenation

Skip

Expression:

Invoke an Expression:

Into Keyword:

Simple query:

Multiple query:

191