<h2>Overview</h2>
<p>One of the things I've asked a lot about on this site is <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx" rel="noreferrer">LINQ</a>. The questions I've asked have been wide and varied and often don't have much context behind them. So in an attempt to consolidate the knowledge I've acquired on Linq I'm posting this question with a view to maintaining and updating it with additional information as I continue to learn about LINQ.</p>
<p>I also hope that it will prove to be a useful resource for other people wanting to learn about LINQ.</p>
<h2>What is LINQ?</h2>
<p>From <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx" rel="noreferrer">MSDN</a>:</p>
<blockquote>
<p>The LINQ Project is a codename for a
set of extensions to the .NET
Framework that encompass
language-integrated query, set, and
transform operations. It extends C#
and Visual Basic with native language
syntax for queries and provides class
libraries to take advantage of these
capabilities.</p>
</blockquote>
<p>What this means is that LINQ provides a standard way to query a variety of datasources using a common syntax.</p>
<h2>What flavours of LINQ are there?</h2>
<p>Currently there are a few different LINQ providers provided by Microsoft:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/bb397919.aspx" rel="noreferrer">Linq to Objects</a> which allows you to execute queries on any IEnumerable object.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" rel="noreferrer">Linq to SQL</a> which allows you to execute queries against a database in an object oriented manner.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx" rel="noreferrer">Linq to XML</a> which allows you to query, load, validate, serialize and manipulate XML documents.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb386964.aspx" rel="noreferrer">Linq to Entities</a> as suggested by <a href="https://stackoverflow.com/questions/16322/all-about-linq#33588">Andrei</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb399399.aspx" rel="noreferrer">Linq to Dataset</a></li>
</ul>
<p>There are quite a few others, many of which are listed <a href="http://blogs.microsoft.co.il/blogs/vardi/archive/2008/10/09/the-linq-list-projects.aspx" rel="noreferrer">here</a>.</p>
<h2>What are the benefits?</h2>
<ul>
<li>Standardized way to query multiple datasources</li>
<li>Compile time safety of queries</li>
<li>Optimized way to perform set based operations on in memory objects</li>
<li>Ability to debug queries</li>
</ul>
<h2>So what can I do with LINQ?</h2>
<p><a href="https://stackoverflow.com/users/489/ch00k">Chook</a> provides a way to <a href="https://stackoverflow.com/questions/4432/csv-string-handling#4441">output CSV files</a><br />
<a href="https://stackoverflow.com/users/1/jeff-atwood">Jeff</a> shows how to <a href="https://stackoverflow.com/questions/9673/remove-duplicates-from-array#9685">remove duplicates from an array</a><br />
Bob gets a <a href="https://stackoverflow.com/questions/59/how-do-i-get-a-distinct-ordered-list-of-names-from-a-datatable-using-linq#62">distinct ordered list from a datatable</a><br />
<a href="https://stackoverflow.com/users/1659/marxidad">Marxidad</a> shows how to <a href="https://stackoverflow.com/questions/15486/sorting-an-ilist-in-c#15495">sort an array</a><br />
Dana gets help implementing a <a href="https://stackoverflow.com/questions/185072/learning-linq-quicksort">Quick Sort Using Linq</a></p>
<h2>Where to start?</h2>
<p><strong>A summary of links from <a href="https://stackoverflow.com/questions/8050/beginners-guide-to-linq">GateKiller's question</a> are below</strong>:<br />
Scott Guthrie provides an <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" rel="noreferrer">intro to Linq on his blog</a><br />
An overview of <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx" rel="noreferrer">LINQ on MSDN</a></p>
<p><strong><a href="https://stackoverflow.com/users/1758/ChrisAnnODell">ChrisAnnODell</a> suggests checking out:</strong></p>
<ul>
<li><a href="http://www.hookedonlinq.com/MainPage.ashx" rel="noreferrer">Hooked on Linq</a></li>
<li><a href="http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b" rel="noreferrer">101 Linq Samples</a></li>
<li><a href="http://www.linqpad.net/" rel="noreferrer">LinqPad</a></li>
</ul>
<h2>What do I need to use LINQ?</h2>
<p>Linq is currently available in VB.Net 9.0 and C# 3.0 so you'll need Visual Studio 2008 or greater to get the full benefits. (You could always write your code in notepad and compile using MSBuild)</p>
<p>There is also a tool called <a href="https://stackoverflow.com/questions/7652/querying-like-linq-when-you-dont-have-linq#7710">LinqBridge</a> which will allow you to run Linq like queries in C# 2.0.</p>
<h2>Tips and tricks using LINQ</h2>
<p><a href="https://stackoverflow.com/questions/28858/coolest-c-linqlambdas-trick-youve-ever-pulled">This question</a> has some tricky ways to use LINQ</p>

[{'answer_id': 33588, 'author': 'Andrei Rînea', 'author_id': 1796, 'author_profile': 'https://Stackoverflow.com/users/1796', 'pm_score': 3, 'selected': False, 'text': '<p>Mention LINQ to Entities since ADO.NET Entity Framework will be an important .NET module.</p>\n'}, {'answer_id': 35584, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 2, 'selected': False, 'text': '<p>Get the book <strong><em>Linq in Action</em></strong> it is an easy read for a coding book and really teaches you how to use Linq and the new features of .NET 3.5 some of the cool parts they put in for the language.</p>\n'}, {'answer_id': 195342, 'author': 'Chris S', 'author_id': 21574, 'author_profile': 'https://Stackoverflow.com/users/21574', 'pm_score': 4, 'selected': False, 'text': '<p>LINQ to entities:</p>\n\n<ul>\n<li><a href="http://blogs.msdn.com/adonet/archive/2008/05/20/how-do-i-new-entity-framework-videos.aspx" rel="noreferrer">Video walkthroughs</a></li>\n<li><a href="http://channel9.msdn.com/shows/Going+Deep/ADONET-Entity-Framework-What-How-Why/" rel="noreferrer">Channel 9 video</a></li>\n<li><a href="http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx" rel="noreferrer">Entity framework FAQ</a></li>\n<li><a href="http://blogs.msdn.com/adonet/archive/2008/03/27/ado-net-entity-framework-performance-comparison.aspx" rel="noreferrer">Entity framework performance</a></li>\n</ul>\n\n<p>I\'ve got a lot more I <a href="http://delicious.com/mrshrinkray/entityframework" rel="noreferrer">tagged on Delicious.com</a>.</p>\n'}, {'answer_id': 272289, 'author': 'DOK', 'author_id': 27637, 'author_profile': 'https://Stackoverflow.com/users/27637', 'pm_score': 2, 'selected': False, 'text': '<p>Some caveats about using <strong>LINQ to SQL</strong>:</p>\n\n<p><a href="https://stackoverflow.com/questions/253263/has-microsoft-really-killed-linq-to-sql">Has Microsoft really killed LINQ to SQL?</a></p>\n\n<p><a href="https://stackoverflow.com/questions/252683/is-linq-to-sql-doa">Is LINQ to SQL DOA?</a></p>\n\n<p>There\'s also some <a href="http://blogs.zdnet.com/microsoft/?p=1457" rel="nofollow noreferrer">controversy</a> about the first version of <strong>Entity Framework</strong>, including a <a href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/" rel="nofollow noreferrer">petition</a>.</p>\n'}, {'answer_id': 715549, 'author': 'Konstantin Tarkus', 'author_id': 82686, 'author_profile': 'https://Stackoverflow.com/users/82686', 'pm_score': 3, 'selected': False, 'text': '<h2>A few LINQ Tips:</h2>\n\n<ul>\n<li>Apply filters before a join to improve query performance</li>\n<li>Filter LINQ queries using object reference comparison</li>\n<li>Apply aggregates to empty collections in LINQ to SQL queries</li>\n<li>Delay loading a property in LINQ to SQL</li>\n<li>Use table-valued functions with eager loading turned on</li>\n<li>Put joins in the correct order in a LINQ to Objects query</li>\n<li>Compose a LINQ query inside a loop</li>\n</ul>\n\n<p><a href="http://www.aspnetpro.com/articles/2009/04/asp200904zh_f/asp200904zh_f.asp" rel="noreferrer">http://www.aspnetpro.com/articles/2009/04/asp200904zh_f/asp200904zh_f.asp</a></p>\n'}, {'answer_id': 1689247, 'author': 'Alexandra Rusina', 'author_id': 198366, 'author_profile': 'https://Stackoverflow.com/users/198366', 'pm_score': 2, 'selected': False, 'text': '<p>I think, the answer to "What flavors of LINQ are there?" is incomplete.\nFirst of all, you can create your own "flavor". Yes, it is an advanced task, but there are a lot of different LINQ implementations now.</p>\n\n<p>Here is the list of existing LINQ providers (plus some more resources on learning LINQ) on Charlie Calvert\'s blog: <a href="http://blogs.msdn.com/charlie/archive/2006/10/05/Links-to-LINQ.aspx" rel="nofollow noreferrer">Links to LINQ</a>.</p>\n\n<p>And also there is an excellent series of blog posts by Matt Warren on how to create your own LINQ Provider: <a href="http://blogs.msdn.com/mattwar/pages/linq-links.aspx" rel="nofollow noreferrer">LINQ: Building an IQueryable provider series</a></p>\n'}, {'answer_id': 1884121, 'author': 'Matthew Sposato', 'author_id': 2287940, 'author_profile': 'https://Stackoverflow.com/users/2287940', 'pm_score': 2, 'selected': False, 'text': '<p>IMHO, an overlooked, but important, benefit is the coding efficiency of LINQ, e.g how much can be accomplished with so little code. I personally find the query syntax easy to read and comprehend.</p>\n'}, {'answer_id': 32990822, 'author': 'refactor', 'author_id': 2693545, 'author_profile': 'https://Stackoverflow.com/users/2693545', 'pm_score': 2, 'selected': False, 'text': '<p>My 2 cents , Read chapters  "11 Query expressions and LINQ to Objects" and "12 LINQ beyond collections" in "C# in Depth" book  to understand how LINQ works.</p>\n'}, {'answer_id': 41905173, 'author': 'BenKoshy', 'author_id': 4880924, 'author_profile': 'https://Stackoverflow.com/users/4880924', 'pm_score': 0, 'selected': False, 'text': '<p><strong>For Linq Practice</strong></p>\n\n<p>If you want some practice on LINQ with exercises and answers, really easy to set up and, in my opinion, awesome:</p>\n\n<p><a href="https://github.com/walkhard/linq-exercises" rel="nofollow noreferrer">https://github.com/walkhard/linq-exercises</a></p>\n\n<p>Download from git, open in Visual Studio. Your job is to make the tests pass.</p>\n\n<p>[disclosure: i learned some linq from it and I contribute to the project so yeah i think it\'s an awesome, fast and efficient way to learn.]</p>\n'}]
['https://Stackoverflow.com/questions/16322', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/493/']