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.
LINQ Basics
What LINQ is, and the difference between the interfaces it hangs off, which is the thing that decides whether your query runs in memory or on the database.
- .NET Collections – IEnumerable, IQueryable, ICollection
- LINQ Basic Concepts
- Advanced LINQ
- Sorting and Filtering With LINQ
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
Performance and Parallel LINQ
LINQ is rarely the bottleneck, and when it is, it is usually one of these four things.
- Any() vs Count() in .NET: Which One is Better?
- Understanding PLINQ
- Extreme LINQ Performance Boost in .NET 7
- LINQ Improvements
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
- Resolving the Call Is Ambiguous Error While Using LINQ
- How to Use the LINQ ToDictionary Method
- Using Dynamic LINQ With System.Linq.Dynamic.Core Library
- 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.
