我如何将以下sql查询转换为LINQ
select *
from groupprincipal.members
where displayname not in (select adusername
from employees)
我想列出Active Directory组中不在employees表中的所有成员
我试过
var notLoggedIn = from groupMembers in groupPrincipal.Members
from loggedIn in employeeRepository.All
where groupMembers.DisplayName != loggedIn.ActiveDirectoryName
select groupMembers;
但是你知道它不起作用。
答案 0 :(得分:2)
var notLoggedIn = from groupMembers in groupPrincipal.Members
where !employeeRepository.Select(p=> p.adUserName).Contains(groupMembers.DisplayName)
select groupMembers;
答案 1 :(得分:1)
我相信应该这样做:
var notLoggedIn =
from groupMembers in groupPrincipal.Members
where !(from loggedIn in employeeRepository.All
select loggedIn.ActiveDirectoryName).Contains(groupMembers.DisplayName)
select notLoggedIn;