【发布时间】:2016-08-04 11:43:29
【问题描述】:
我有一个投影函数,我传递给IQueryable<>.Select() 方法:
private static Expression<Func<VendorPrice, PriceItem>> GetPriceSelector(){
return e => new PriceItem {
Id = e.Id,
Price = Math.Round(e.Price, 4)
};
}
一切正常,但我想像这样参数化它:
private static Expression<Func<VendorPrice, PriceItem>> GetPriceSelector(Func<VendorPrice, decimal> formula){
return e => new PriceItem {
Id = e.Id,
Price = formula(e)
};
}
所以我可以这样称呼它
prices.Select(GetPriceSelector(e => Math.Round(e.Price, 4)))
不幸的是,EF 抱怨它:
LINQ 不支持 LINQ 表达式节点类型“Invoke” 实体
如何重写代码让EF开心?
【问题讨论】:
标签: c# entity-framework linq entity-framework-6 expression-trees