A lot of posts have been flying around lately, with different performance numbers for Linq 2 Sql. Some close to abysmal, and some showing pretty good performance.
Its important to realize that behind the scenes, .Net 3.5 creates a sql statement from the Linq query syntax and calls a SqlDataReader to iterate over the results after execution. The most common numbers we see is that Linq is about 53% slower than native Ado.net.
The biggest penalty we see for performance comes from building and parsing the queries. But what if we could somehow prepare the statements for execution ahead of time.. Sort of like … compiling them.
Well you can, using the Compile function of a query. Using the compile feature of Linq 2 Sql performance get close to 93% of the native ado.net code.
However I am unsure of the real value in doing this. Unless the exact same query is executed many times with no changes, there will be little benefit to pre-compiling the queries.
Simply separating the steps of execution and query preparation makes little sense unless you need a durable query to be used several times.
A great source for performance numbers for Linq to Sql is Rico Mariani