如何在MS SQL中编写与此子选项等效的linq语句:
... WHERE
tblXref.Organization_Id IN (SELECT Organization_Id
FROM AppUser au INNER JOIN [User] u ON au.User_Id = u.Id
WHERE u.Username = usernameVariable)
答案 0 :(得分:5)
嗯,单独编写内部查询可能更简单(记住你不是执行查询):
var innerQuery = from au in db.AppUsers
join u in db.Users on au.User_Id equals u.Id
where u.UserName == userNameVariable
select au.Organization_Id;
var query = from tblXref in db.CrossReferences // or whatever
where innerQuery.Contains(tblXref.Organization_Id)
...;