Knowing how to use Linq is useful if you're doing any coding using .NET 3.5 or newer. But have you ever thought about what is going on "under the hood"?
Join us as we dive into the guts of Linq and implement Linq extension methods such as Where, Select, Any, All and Aggregate. Not only is it interesting to see what's going on, it'll help you to build better code using Linq.
1. Linq (from the inside)
Reinventing the Linq to Objects wheel
Mike Clement
mike@softwareontheside.com
@mdclement
2.
3.
4.
5.
6.
7. LINQ to Amazon LINQ to Metaweb(freebase)
LINQ to Active Directory LINQ to MySQL, Oracle and
LINQ to Bindable Sources (SyncLINQ) PostgreSql (DbLinq)
LINQ to C# project LINQ to NCover
LINQ to Continuous Data (CLinq) LINQ to Opf3
LINQ to CRM LINQ to Parallel (PLINQ)
LINQ To Geo - Language Integrated Query for LINQ to RDF Files
Geospatial Data LINQ to Sharepoint
LINQ to Excel LINQ to SimpleDB
LINQ to Expressions (MetaLinq) LINQ to Streams
LINQ Extender (Toolkit for building LINQ LINQ to Twitter
Providers) LINQ to WebQueries
LINQ to Flickr LINQ to WMI
LINQ to Google http://tomasp.net/blog/linq-
LINQ to Indexes (LINQ and i40) expand.aspx
LINQ to IQueryable (Matt Warren on http://tomasp.net/blog/linq-expand-
Providers) update.aspx
LINQ to JSON Linq To WIQL
LINQ to LDAP LINQ to XtraGrid
LINQ to NHibernate
LINQ to JavaScript Source:
LINQ to LLBLGen Pro http://blogs.msdn.com/b/charlie/archive/20
LINQ to Lucene 06/10/05/links-to-linq.aspx
8. If I have seen
further it is by
standing on the
shoulders of giants.
-Sir Issac Newton
10. • Jon Skeet is immutable. If something’s going to change, it’s going
to have to be the rest of the universe.
• Jon Skeet is the only top 100 SO user who is human. The others
are bots that he coded to pass the time between questions.
• Jon Skeet does not use revision control software. None of his
code has ever needed revision.
• When Jon Skeet’s code fails to compile, the compiler apologizes.
• Jon Skeet is the traveling salesman. Only he knows the shortest
route.
• The Dining Philosophers wait while Jon Skeet eats.
• When Jon Skeet points to null, null quakes in fear.
• Jon Skeet does not use exceptions when programming. He has
not been able to identify any of his code that is not exceptional.
11. • Jon Skeet has already written a book about
C# 5.0.
• It’s currently sealed up.
• In three years, Anders Hejlsberg is going to
open the book to see if the language design
team got it right
12. from cust in customers
where cust.City == "London"
select cust;
customers.Where(
cust => cust.City == "London");
22. Resources
• Classification by Manner of Execution
• C# Features
• List of Linq Providers (and other links)
• EduLinq code blog posts (from Jon Skeet)
• MoreLinq (from Jon Skeet)
• My Starter Project
– https://github.com/mdclement/Linq--from-the-
inside--Presentation-Base
23. Action Items!
• Read Jon Skeet’s EduLinq series.
• Download my “starter” and play!
• If you aren’t already, use Linq in your everyday
coding.
• Look for other Linq operators to implement.
• Attend the Utah Software Craftsmanship
Group!
24. Me
• @mdclement
• mike@softwareontheside.com
• http://blog.softwareontheside.com
• Utah Software Craftsmanship Group
– https://groups.google.com/forum/#!forum/ut-
software-craftsmanship
– @utahsc
– First Wednesday, Neumont, Room 300
Notas do Editor
Not Link cosplay! Not that there’s anything wrong with that…
The “other” Microsoft “link”
Language-Integrated QueryQuery is first class citizen in languageQueries are consistent across data sourcesOne query language to rule them all
Don’t want to get too far in without recognizing the true brains behind this presentation.
Monster on StackOverflowWrote “C# In Depth” (excellent read… I need to pick up the second edition)Wrote the Edulinq blog posts (and project that I’m based on today)
http://msdn.microsoft.com/en-us/library/bb882642.aspxSo back to Linq…Query Expression Syntax vs. Extension MethodsNote that given the providers, “customers” could be XML, a database, a web service…But then they split it into two different syntaxes? Syntacies?“real” linq (integrated query) only supports a subset of what the full extension methods support.
These language features are used to implement Linq either explicitly or “from the inside”Query syntax inlinevar keywordCustomer cust = new Customer { Name = "Mike", Phone = "555-1212" };An anonymous type is constructed by the compiler and the type name is only available to the compiler. Anonymous types provide a convenient way to group a set of properties temporarily in a query result without having to define a separate named type. An extension method is a static method that can be associated with a type, so that it can be called as if it were an instance method on the type. This feature enables you to, in effect, "add" new methods to existing types without actually modifying them.A lambda expression is an inline function that uses the => operator to separate input parameters from the function body and can be converted at compile time to a delegate or an expression tree.the compiler will create a private, anonymous backing field that is not accessible except through the property getter and setter.
Linq operators are defined as extension methods on IEnumerable<T>So it’s important that we understand the anatomy of extension methods.Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.
Going to pull back the curtain
Unfortunately it may feel like this for a little bit…House in Poland
Going to pull back the curtain
These language features are used to implement Linq either explicitly or “from the inside”Query syntax inlinevar keywordCustomer cust = new Customer { Name = "Mike", Phone = "555-1212" };An anonymous type is constructed by the compiler and the type name is only available to the compiler. Anonymous types provide a convenient way to group a set of properties temporarily in a query result without having to define a separate named type. An extension method is a static method that can be associated with a type, so that it can be called as if it were an instance method on the type. This feature enables you to, in effect, "add" new methods to existing types without actually modifying them.A lambda expression is an inline function that uses the => operator to separate input parameters from the function body and can be converted at compile time to a delegate or an expression tree.the compiler will create a private, anonymous backing field that is not accessible except through the property getter and setter.