我检索两个不同的仓库数据:LINQ查询优化
List<F> allFs = fRepository.GetFs().ToList();
List<E> allEs = eRepository.GetEs().ToList();
现在我需要加入他们的行列,所以我做了以下内容:
var EFs = from c in allFs.AsQueryable()
join e in allEs on c.SerialNumber equals e.FSerialNumber
where e.Year == Convert.ToInt32(billingYear) &&
e.Month == Convert.ToInt32(billingMonth)
select new EReport
{
FSerialNumber = c.SerialNumber,
FName = c.Name,
IntCustID = Convert.ToInt32(e.IntCustID),
TotalECases = 0,
TotalPrice = "$0"
};
我怎样才能让这个LINQ查询更好,所以它会跑得更快?我将不胜感激任何建议。
感谢
什么'fRepository'和'eRepository'?他们返回什么? – 2012-04-18 20:09:02
你为什么要做“ToList()”?这将立即执行查询并返回allFs和allEs。 – Robaticus 2012-04-18 20:10:54
对不起,他们返回IQueriable和IQueriable s –
Sev
2012-04-18 20:11:10