varunmaggo's say

Getting better never stops!

Speed Up Your LINQ Statements with “Let”

leave a comment »

This post being last post of the year 2011. Have a great going for year 2012! Wish all of you a happy prosperous new year :)

Using Linq Let keyword :

Old way :
var cheapCategories = from cat in Categories
where cat.Products.Average(p => p.Price) p.Price) };

New Way :
var cheapCategories = from cat in Categories
let AvgPrice = cat.Products.Average(p => p.Price)
where AvgPrice < 100
select new { cat.Name, AvgPrice };
Its code is pretty straight forward to the point!

Advertisement

Written by Varun Maggo

December 31, 2011 at 9:02 am

Posted in Uncategorized

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.