Sunday, October 19, 2008

Lambda Expression and LINQ Extension

As I learn more about LINK I hope these things become more of an automatic choice rather than keeping notes... but for now I am stil new to LINQ:

You can use two different ways to retrieve items from a database. The first one is uses the DataContext to call the stored procedure and in a LINQ syntax:

NorthwindDataContext db = new NorthwindDataContext();
var results = from item in db.CustOrderHist("category")
where item.Total > 10
select item;

and the second way is to use the extension with a lumbda expression:

results = db.CustOrderHist("category")
.where (item => Item.Total > 10);

I still havn't figure out which one has which benefits comparing the other way.

No comments: