[摘抄] 为什么 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 ?的主要内容,如果未能解决你的问题,请参考以下文章

Linq2DB之研究和探索

有没有啥简单的方法可以在 Linq 中实现 SQL Server 的合并查询?

精华摘抄SQL查询重复记录

优化 LINQ 查询所需的帮助

Linq to SQL中如何拦截和修改SQL查询

什么都2020了,LINQ查询你还在用表达式树