2. What is LINQ?
Language Integrated Query - part of Microsoft .NET Framework
Formulate queries directly in C# and VB instead of SQL
LINQ-to-objects (in-memory data)
LINQ-to-entities (ORM <-> SQL)
3. Why LINQ?
No need to learn a new query syntax, use your C# programming chops.
Single, consistent query language for working with data - in memory or in databases.
Widely used, adapters for most databases you can think of:
MySQL, MariaDB, MSSQL, PostgreSQL, MongoDB, CouchDB, ...
4. LINQ - Two tales of syntax
Query syntax - “SQL-like”
Method syntax - “C#-like”
7. LINQ - Operations
Ordering
Join
GroupBy
Aggregates - Min, Max, Sum, Count, Average
Set - Union, Distinct, Intersect, Except
Element - First, FirstOrDefault, Last, LastOrDefault
Qualifiers - Any, All, Contains
Partitioning - Take, Skip
Conversions - ToList, ToDictionary, ToArray, Cast<T>, OfType<T>
8. Extending LINQ-to-objects
It is all about IEnumerable
Nugets: MoreLINQ
Writing your own Prepend()
This won’t work against databases!
9. LINQ-to-entities (databases)
Requires an ORM, Entity Framework ships with .NET for SQL
Has adapters to all the popular databases, MSSQL, MySQL, MariaDB, PostgreSQL…
LINQ is translated to SQL, so this doesn’t work
But this does:
11. LINQPad
Awesome C# and LINQ scratchpad.
Test out C#, F#, VisualBasic code-snippets
Test out queries with LINQ, SQL, ESQL against databases
Navigate the database from any result set, follow relations and dig deep into the data
Intellisense and supports nugets
Showtime!