Estoy tratando de obtener un recuento total de registros del siguiente método utilizando EntityFramework y Linq. Es lento devolver un conteo.Linq Seleccionar instrucción lenta al obtener 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();
}
}
Aquí está una manera de acelerarlo, combina las consultas .Where en una. Acabo de leer un artículo sobre esto en realidad. 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 + Codificación + Blog% 29 – m4tt1mus