[Excerpt] Why LINQ can query SQL efficiently?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.