Linq Sum动态参数

时间:2017-10-22 13:52:21

标签: c# entity-framework linq sum linq-to-entities

Func<FooEntity, double> selector = null;
selector = x => x.M1_TotalLoss;

var entity = FooEntity
    .Where(x => x.Year == year)
    .GroupBy(gp => gp.Year)
    .Select(ss => new FooDto
    {
        SumTotalLoss = ss.Sum(selector)
    })
    .FirstOrDefaultAsync();

我需要总和动态选择器。

错误=内部.NET Framework数据提供程序错误1025.

1 个答案:

答案 0 :(得分:0)

ss.AsQueryable().Sum(selector)