首页 > 数据库技术 > 详细

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

时间:2016-05-30 12:52:30      阅读:196      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!