From C # in Depth (3rd)-Jon Skeet
using (Linqdemodatacontext db = new Linqdemodatacontext ()) {var filtered = from P in db. Productsjoin s in db. Supplierson P.supplierid equals S.supplieridwhere p.price > 10orderby s.name, p.nameselect new {suppliername = S.Name, ProductName = P.name};foreach (var v in filtered) {Console.WriteLine ("supplier={0}; Product={1} ", V.suppliername, V.productname);}}
That's impressive enough, but if you ' re performance-conscious, you'll be wondering
Why do you ' d want-pull down all the data from the database and then apply
these. NET queries and orderings. Why isn't get the database to do it? That's what it ' s
Good at, isn ' t it? Well, Indeed-and that's exactly what the LINQ to SQL does. The code in
Listing 1.18 issues a database request, which is basically the query translated into SQL.
Even though you ' ve expressed the query in C # code, it's been executed as SQL.
[Excerpt] Why LINQ can query SQL efficiently?