我被这个 linq 查询卡住了,我只需要优化最后的价格计算,因为我得到了大约 1000 篇文章,而且销售量很大,所以它变慢了......
var result = from article in db.Entities.Articles
select new{
article.ID_ART,
article.Designation,
article.BuyPrice,
article.SellPrice,
LastPrice = (from sale in article.Sales where sale.Date == article.Sales.Max(X => X.Date) select sale.Price).FirstOrDefault()==0?
article.BuyPrice: (from sale in article.Sales where sale.Date == article.Sales.Max(X => X.Date) select sale.Price).FirstOrDefault()
}