码迷,mamicode.com
首页 > 数据库 > 详细

[摘抄] 为什么 Linq 可以高效率查询 SQL ?

时间:2016-05-30 12:55:19      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:

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 ?

标签:

原文地址:http://www.cnblogs.com/yangyangss/p/5541948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!