如何使用 lambda 表达式将此 linq 查询重写为 Entity?
我想在我的 lambda 表达式中使用let关键字或等效关键字。
var results = from store in Stores
let AveragePrice = store.Sales.Average(s => s.Price)
where AveragePrice < 500 && AveragePrice > 250
对于一些类似的问题,例如我的问题下评论的内容,建议
.Select(store=> new { AveragePrice = store.Sales.Average(s => s.Price), store})
它将计算每个项目的 AveragePrice,而在我提到的查询样式中,让表达式防止多次计算平均值。