我有以下sql查询,我无法将其翻译为正确的linq语句。
SELECT
r.RoleName,
uir.UserId
FROM
webpages_Roles r
LEFT JOIN webpages_UsersInRoles uir ON uir.RoleId = r.RoleId
AND r.AppId = 1
WHERE
uir.UserId IS NULL
在我的c#中,我有类似的东西:
IEnumerable<Role> roles = uow.RolesRepository.Get(r => r.AppId == 1 && r.UsersInRoles.Any(uir => uir.UserId == null), includeProperties: "UsersInRoles");
我正在使用存储库,但也可能是:
IEnumerable<Role> roles = context.Roles.Where(r => r.AppId == 1 && r.UsersInRoles.Any(uir => uir.UserId == null));
答案 0 :(得分:1)
尝试:
Enumerable roles = context.Roles
.Where(r => r.AppId == 1 && !r.UsersInRoles.Any(uir => uir.UserId != null));