简而言之,您不能对匿名类型使用CompliedQuery,您需要让查询返回一个命名类型,因此
select new
{
FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0),
CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0),
grp.Key.TestResults,
grp.Key.FailStep,
PercentFailed = Convert.ToDecimal(1.0 * grp.Count() / tcount * 100)
}
select new MyType
{
FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0),
CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0),
TestResults = grp.Key.TestResults,
FailStep = grp.Key.FailStep,
PercentFailed = Convert.ToDecimal(1.0 * grp.Count() / tcount * 100)
}
你的最后一个泛型参数
Func<>
IQueryable<MyType>
同样,因为这就是您的查询现在返回的结果。
在这种情况下,
MyType
看起来像:
public class MyType {
public int FailedCount { get; set; }
public int CancelCount { get; set; }
public string TestResults { get; set; }
public string FailStep { get; set; } //Unsure of type here
public decimal PercentFailed { get; set; }
}