烦人的表达式转化错误
var query1= emps.Grouby(v=>v.DeptId).Select(g=>new { DeptId=g.Key,Salary=g.Max(x=>x.Salary); var result=from d in depts join q in query1 on d.Id equals q.DeptId select new { d.Name,q.Salary};
上面代码运行起来,EF Core绝对说表达式树无法翻译,为什么呢?
因为query1
是匿名类型,也就是说DeptId
可空,就等下面表达式的d.Id
类型不匹配,因此只需要select
是强类型就好了
var query1= emps.Grouby(v=>v.DeptId).Select(g=>new Emp{ DeptId=g.Key,Salary=g.Max(x=>x.Salary); var result=from d in depts join q in query1 on d.Id equals q.DeptId select new { d.Name,q.Salary};
参考:https://www.cnblogs.com/ShuiSen/p/16989903.html
标签:DeptId,Core,query1,EF,var,Salary,new,groupby
From: https://www.cnblogs.com/ccprince/p/17789111.html