LINQ and LINQPad
-
Upload
andreas-gullberg-larsen -
Category
Software
-
view
30 -
download
1
Transcript of LINQ and LINQPad
LINQAndreas Gullberg Larsen
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)
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, ...
LINQ - Two tales of syntaxQuery syntax - “SQL-like”
Method syntax - “C#-like”
LINQ - OperationsSelect (map)
SelectMany (flatten)
LINQ - OperationsWhere (filter)
Aggregrate (reduce)
LINQ - OperationsOrdering
JoinGroupByAggregates - Min, Max, Sum, Count, AverageSet - Union, Distinct, Intersect, ExceptElement - First, FirstOrDefault, Last, LastOrDefaultQualifiers - Any, All, ContainsPartitioning - Take, SkipConversions - ToList, ToDictionary, ToArray, Cast<T>, OfType<T>
Extending LINQ-to-objectsIt is all about IEnumerable
Nugets: MoreLINQ
Writing your own Prepend()
This won’t work against databases!
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:
LINQ-to-entities (databases)LINQ is lazy, no query is run until you call .ToList().
LINQPadAwesome 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!