0

以下 SQL 语句对应的 linq2sql 语句是什么?

SELECT id, userName
FROM users
WHERE
  (SELECT COUNT(*) FROM logins WHERE logins.userId=users.id) > 0

或写成连接:

SELECT id, userName
FROM users 
LEFT JOIN logins ON logins.id=(SELECT MIN(id) FROM logins WHERE userId=users.id)
WHERE logins.id IS NOT NULL

谢谢

4

1 回答 1

1

假设您的上下文中有“用户”和“登录”DBSet,并且您的上下文的名称是“上下文”:

var result = from user in context.users
             where (from  login in context.logins
                     where login.userId = user.userId
                     select login).Count() > 0
             select user.Id,userName
于 2013-09-12T11:12:16.067 回答