我想从下面的方法使用EntityFramework和Linq获得总记录数。返回计数很慢。Linq选择语句慢时得到COUNT
public static int totalTracking(int id)
{
using (var ctx = new GPEntities())
{
var tr = ctx.Tracking
.Where(c => c.clientID == Config.ClientID)
.Where(c => c.custID == id)
.Where(c => c.oOrderNum.HasValue)
.ToList();
return tr.Count();
}
}
继承人一个办法,加快步伐,将查询合并为一个。我刚刚读了一篇关于这个的文章。 http://msmvps.com/blogs/jon_skeet/archive/2011/06/16/linq-to-objects-and-the-performance-of-nested-quot-where-quot-calls.aspx?utm_source=feedburner&utm_medium = feed&utm_campaign = Feed%3A + JonSkeetCodingBlog +%28Jon + Skeet%27s +编码+博客%29 – m4tt1mus 2011-06-17 00:08:04