我有一个查询,就像这样
var ReportData = db.PY_History_TransactionTAB.AsEnumerable()
.Where(x => x.SystemCode == SysCode)
.GroupBy(x => new { x.EmployeeCode, x.EmployeeMaster.Emp_FullName});
对于x.EmployeeCode
选择GroupBy成员,很容易做到:
ReportData.Select(x => new PY_History_TransactionTAB
{
EmployeeCode = x.Key.EmployeeCode,
}
但是,如果我想选择下一个GroupBy成员即x.EmployeeMaster.Emp_FullName
,该怎么办呢?所以我在强烈的类型视图中做到了。
答案 0 :(得分:0)
ReportData.Select(x => new
{
EmployeeCode = x.Key.EmployeeCode,
EmployeeName = x.Key.Emp_FullName,
}
答案 1 :(得分:0)
我找到了解决方案。因此,如果您有导航属性,只需将其放在select()中即可:
ReportData.Select(x => new PY_History_TransactionTAB
{
EmployeeCode = x.Key.EmployeeCode,
EmployeeMaster = x.First().EmployeeMaster
}
现在您可以拥有EmployeeMaster
类的所有属性。