LINQ is a query syntax built into C#. It lets you ask a question of a collection, a database or an XML document using the same set of methods, and it reads close enough to English that a query usually explains itself.
Most LINQ methods are lazy. Nothing happens until you enumerate the result, so a query you build in one place can run somewhere else entirely. ToList and ToArray force it to run now.
LINQ to Objects and LINQ to Entities look identical on the page. Against a collection your code runs in memory. Against a database the same expression is translated into SQL, so some perfectly valid C# will simply fail to translate. The join and grouping articles below cover where the two diverge.
All ten LINQ articles are below.
Filtering and Projecting
Choosing which items you want, and reshaping them on the way out.
- Select vs SelectMany
- The LINQ Where Method
- How to Select Multiple Records Based on a List of IDs Using LINQ
- How to Use SQL LIKE Operator With LINQ
- Execute the SELECT WHERE NOT EXIST SQL Query Using LINQ
Joining and Grouping
Putting two sequences together, and splitting one into buckets.
- How to Create an Outer Join in LINQ – (Left and Right)
- Different Ways to Get the First Record in Each Group With LINQ
- How to Do an Inner Join in LINQ?
Comparing and Converting Results
Finding differences between two sequences, turning a query into a dictionary, and processing results in batches.
- The LINQ Except Method
- LINQ Basic Concepts
- How to Use the LINQ ToDictionary Method
- How to Divide Data Into Batches With LINQ
Where to Go Next
What LINQ is usually querying:
When a query needs a comment to explain it, split it into two queries with names. It costs nothing at runtime and saves the next person who reads it.
