以下SQL语句的对应linq2sql-Statement是什么?
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
THX
答案 0 :(得分:1)
假设您的上下文中有“user”和“login”DBSet,并且您的上下文的名称是“context”:
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