我正在尝试对 LINQ 执行这个简单的 sql 查询。但它给了我错误。
这是需要转换为 LINQ 的 SQL 查询
DECLARE @groupID int
SET @groupID = 2
SELECT *
FROM dbo.Person p
LEFT JOIN dbo.PersonGroup pg ON ( p.PersonID = pg.PersonID AND pg.GroupID = @groupID)
忽略@groupID。它将作为 LINQ 查询的函数参数提供。
这是我尝试过的 LINQ 查询。
from p in Person
join pg in PersonGroup on new { p.PersonID, groupID } equals new { pg.PersonID, pg.GroupID } into t
from rt in t.DefaultIfEmpty()
其中 groupID 作为函数参数提供。 GroupID 和 PersonID 都是 int。但它给了我以下错误,
Error 2 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.
一点帮助将不胜感激。
你的代码
from p in Person
join pg in PersonGroup on new { p.PersonID, groupID } equals new { pg.PersonID, pg.GroupID } into t
from rt in t.DefaultIfEmpty()
将其更改为
from p in Person
join pg in PersonGroup on new { Person = p.PersonID, Group = groupID } equals new { Person = pg.PersonID, Group = pg.GroupID } into t
from rt in t.DefaultIfEmpty()
这样它将使用匿名类型加入
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)