What is "linq"

LINQ, entered in , is a Domain Specific Language (Domain Specific Language; DSL) based on . NET to query data sources such as databases, XML files or lists of objects in memory. All of these data sources can be queried using exactly the same easy-to-use, readable syntax - or better, syntax, because LINQ supports two notations:

  • LINQ aligned or query syntax (query), where queries are expressed in a language similar to SQL dialects in both C# and VB.Net.

  • LINQ operators or fluent query where queries are expressed as lambda expressions and can be linked (Linqed?) using a fluent syntax.

Some examples:

Fluent syntax (C#)

var result = dbContext.Products
    .Where(p => p.Category.Name == "Toys" && p.Price >= 250)
    .Select(p => p.Name);

Query syntax (C#)

var result =
    from product in dbContext.Products
    where product.Category.Name == "Toys"
    where product.Price >= 2.50
    select product.Name;

Query syntax (VB.NET)

Dim result = _
    From product in dbContext.Products _
    Where product.Category.Name = "Toys" _
    Where product.Price >= 2.50 _
    Select product.Name

Variants

LINQ comes in many variants of data collections, the most notable are:

There are other implementations of LINQ, which can be found on the Internet, such as LINQ to Sharepoint, LINQ to Twitter, LINQ to CSV, LINQ to Excel, LINQ to JSON and LINQ to Google.

Tools