[摘抄] 为什么 Linq 可以高效率查询 SQL ?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[摘抄] 为什么 Linq 可以高效率查询 SQL ?相关的知识,希望对你有一定的参考价值。
From C# in Depth(3rd) - Jon Skeet
using (LinqDemoDataContext db = new LinqDemoDataContext()) { var filtered = from p in db.Products join s in db.Suppliers on p.SupplierID equals s.SupplierID where p.Price > 10 orderby s.Name, p.Name select 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 may be wondering
why you’d want to pull down all the data from the database and then apply
these .NET queries and orderings. Why not get the database to do it? That’s what it’s
good at, isn’t it? Well, indeed—and that’s exactly what 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.
以上是关于[摘抄] 为什么 Linq 可以高效率查询 SQL ?的主要内容,如果未能解决你的问题,请参考以下文章