LINQ query syntax and query expression

With built-in LINQ extension methods and lambda expressions, Visual Studio allows us to write SQL-like statements in C# when invoking these methods. The syntax of these statements is called LINQ query syntax and the expression in query syntax is called a query expression.

For example, we can change the following statement:

var veges6 = products.Where(p => p.ProductName.Contains("vegetable"));

To the following query statement by using the LINQ query syntax:

var veges7 = from p in products
             where p.ProductName.Contains("vegetable")
             select p;

In the above C# statement, we can directly use the SQL keywords select, from, and where to "query" an in-memory collection list. In addition to the in-memory collection lists, ...

Get WCF 4.5 Multi-Layer Services Development with Entity Framework now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.