LINQ to Entities Group By表达式给出'匿名类型投影初始值设定项应该是简单名称或成员访问表达式'

esa*_*sac 16 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
    };
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*ott 42

做类似的事情:

select new
{
    d.Key,
    Sum = d.Sum(x => x.InclusiveDurationMilliseconds)
};
Run Code Online (Sandbox Code Playgroud)

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

  • 正如您发布的那样想出的..其中之一是深夜需要咖啡的心事单。谢谢。为您简单点:) (2认同)