LINQ Query Syntax
There are two basic ways to write a LINQ query to IEnumerable collection or IQueryable data sources.
Query Syntax or Query Expression Syntax
Method Syntax or Method Extension Syntax or Fluent
Query Syntax
Query syntax is similar to SQL (Structured Query Language) for the database. It is defined within the C# or VB code.LINQ Query Syntax:
The LINQ query syntax starts with from keyword and ends with select keyword. The following is a sample LINQ query that returns a collection of strings which contains a word "Tutorials".
The following figure shows the structure of LINQ query syntax.LINQ Query Syntax
Query syntax starts with a From clause followed by a Range variable. The From clause is structured like "
From
rangeVariableName
in
IEnumerablecollection"
. In English, this means, from each object in the collection. It is similar to a foreach loop: foreach(Student s in studentList)
.
Last updated