c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

标签 c# linq-to-entities

我在这个表达式中遇到了上述错误:

var aggregate = from t in entities.TraceLines
    join m in entities.MethodNames.Where("it.Name LIKE @searchTerm", new ObjectParameter("searchTerm", searchTerm)) on t.MethodHash equals m.MethodHash
    where (t.CallTypeId & (int)types) == t.CallTypeId && t.UserSessionProcessId == m_SessionId
    group t by m.Name into d                                                   
    select new
    {
        d.Key,                                     
        d.Sum(x => x.InclusiveDurationMilliseconds) // <- squigglies on this line
    };

知道是什么导致了这个错误吗?

最佳答案

做类似的事情:

select new
{
    d.Key,
    Sum = d.Sum(x => x.InclusiveDurationMilliseconds)
};

它可以从另一个属性中投影属性名称,但不能从方法中投影....

关于c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3097385/

相关文章:

c# - LINQ to Entities,连接两个表,然后分组并从两个表中获取列的总和

c# - Entity Framework .Where 方法链接

c# - 防篡改表

c# - Linq 查询的复杂性限制

c# - 使用 Linq to Entities (EF6) 动态选择列名

linq-to-entities - LINQ ".Include"子查询中的 orderby

mysql - 在 LINQ 中执行 FirstOrDefault 的替代方法

c# - 如何找到覆盖多边形的圆的最小扇区?

c# - Xamarin.Forms 命令绑定(bind) TargetInvocationException

c# - Nlog 从 Appsettings 获取 Azure Blob 存储连接字符串