# Tuesday, April 21, 2009

Stumbled upon this today, and while I am not too heavily using LINQ at the moment, I know I will be at some point and this will come in handy; perhaps you might find it useful as well. From Joseph Albahari's website, his intro to his page on 10 myths about LINQ:

Here are ten root causes of the most common misunderstandings-distilled from many hundreds of questions on the LINQ forums.

In case you want it, I created a PDF of the same page, cleaned up a bit.

Here are the 10, presented with only their descriptions:

  1. All LINQ queries must start with the 'var' keyword. In fact, the very purpose of the 'var' keyword is to start a LINQ query!
  2. All LINQ queries must use query syntax.
  3. To retrieve all customers from the customer table, you must perform a query similar to the following:
           var query = from c in db.Customers select c;
  4. To reproduce a SQL query in LINQ, you must make the LINQ query look as similar as possible to the SQL query.
  5. To do joins efficiently in LINQ, you must use the join keyword.
  6. Because SQL emits flat result sets, LINQ queries must be structured to emit flat result sets, too.
  7. To do outer joins in LINQ to SQL, you must always use DefaultIfEmpty().
  8. A LINQ to SQL query will be executed in one round-trip only if the query was built in a single step.
  9. A method cannot return a query, if the query ends in the 'new' operator.
  10. The best way to use LINQ to SQL is to instantiate a single DataContext to a static property, and use that shared instance for the life of the application.
Brothers Joseph Albahari & Ben Albahari are the authors of "C# 3.0 in a Nutshell, 3rd Edition," among other books published by my favorite book publisher.
Kick It on DotNetKicks.com
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, i, strike, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Live Comment Preview