The type of one of the expressions in the join clause is incorrect in Entity Framework. Constant in left join

限于喜欢 提交于 2020-04-21 08:14:14

问题


I'm trying to do a left join in an EF query. I'm getting the following error:

Error CS1941 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'

and here is the C# code:

var foo = from m in db.ClientMasters
                      join a in db.Orders on new { m.Id, Status = "N" } equals new { a.ClientID, a.Status } into a_join
                      from a in a_join.DefaultIfEmpty()
                      select new { m.ClientID, a.ID };

回答1:


I'm an idiot. The column names have to match in the join. here is the corrected code.

var foo = from m in db.ClientMasters
                      join a in db.Orders on new { ClientID = m.Id, Status = "N" } equals new { a.ClientID, a.Status } into a_join
                      from a in a_join.DefaultIfEmpty()
                      select new { ClientID = m.Id, OrderId = a.Id };


来源:https://stackoverflow.com/questions/33370600/the-type-of-one-of-the-expressions-in-the-join-clause-is-incorrect-in-entity-fra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!