这里被简化代码实体框架执行表达
from oi in orderItems
group oiGrouped by ...
into orderItemsGroupedBySomething
select new
{
Key = orderItemsGroupedBySomething.Key,
Revenue = /*Here is some code that I want to extract to separate method, for example*/
orderItemsGroupedBySomething.Sum(x => x.UnitPrice * x.Quantity)
}
其实这是在我的情况更加复杂。但我认为这并不重要。我无法提取到orderItemsGroupedBySomething.Sum(x => x.UnitPrice * x.Quantity)
的简单方法计算,因为它不是EntityFramework的已知方法。我试图把它表达,但我得到错误"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."
我编译表达式之前在查询中使用它,我想因此我得到错误。我怎么解决这个问题?
当你编译一个'表达>'你实际上得到了'Func键<>',而不是一个表达式树,实体框架可以检查和翻译。 –
@LorentzVedeler是的,你是对的。有没有其他的方式来执行它? –