1

您如何编写一个 linq 语句,在 MS SQL 中执行与此子选择等效的操作:

... 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)
4

1 回答 1

4

好吧,单独编写内部查询可能更简单(记住您没有执行查询):

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)
            ...;
于 2013-03-09T19:13:40.093 回答