Wesley Bakker

Interesting things I encounter doing my job...

Sponsors

News

Wesley Bakker
motion10
Rivium Quadrant 151
2909 LC Capelle aan den IJssel
Region of Rotterdam
The Netherlands
Phone: +31 10 2351035

(feel free to chat with me)

Add to Technorati Favorites

How to make a Linq to Sql query twice as fast…

An important action with every LinqToSql query is to transform your lambda’s into T-SQL. In simple queries this can take half of the time. By compiling the query you can cache the result of this transformation which saves a lot of processing time on each succeeding query.

image

There’s a nice write-up over here on how to compile your queries at :http://aspguy.wordpress.com/2008/08/15/speed-up-linq-to-sql-with-compiled-linq-queries/

There’s one tip though I like to mention. If you use simple filter criteria you do not need to create a special SearchCriteria class as mentioned in the post.

var countByCityName = CompiledQuery.Compile(
                        (AdventureWorksDataContext dc, string cityName) =>
                            (from CustomerAddress a in dc.CustomerAddresses
                             where a.Address.City == cityName
                             select a).Count()
                      );
Posted: Jul 30 2009, 10:54 AM by webbes | with 5 comment(s)
Filed under: ,

Comments

How to make a Linq to Sql query twice as fast??? - Wesley Bakker said:

Pingback from  How to make a Linq to Sql query twice as fast??? - Wesley Bakker

# July 30, 2009 5:18 AM

How to make a Linq to Sql query twice as fast??? | ASP Scribe said:

Pingback from  How to make a Linq to Sql query twice as fast??? | ASP Scribe

# July 30, 2009 5:40 AM

How to make a Linq to Sql query twice as fast??? | I love .NET! said:

Pingback from  How to make a Linq to Sql query twice as fast??? | I love .NET!

# July 30, 2009 7:26 AM

Dew Drop – July 30, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop – July 30, 2009 | Alvin Ashcraft's Morning Dew

# July 30, 2009 8:17 AM

How to make a Linq to Sql query twice as fast??? | rapid-DEV.net said:

Pingback from  How to make a Linq to Sql query twice as fast??? | rapid-DEV.net

# July 30, 2009 12:56 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)