linq等效sql查询“不在(选择查询)”

时间:2012-12-22 09:15:32

标签: .net sql linq

我的sql代码如下:

select UserId,UserName 
from aspnet_Users 
where UserId not in (select UsersId from tbluser  where active='true')

什么是等效的linq表达式?

2 个答案:

答案 0 :(得分:11)

我第一次尝试在LiNQ

中使用C#
var result = from y in aspnet_Users
            where !(
                        from x in tblUser
                        where  x.active == "true"
                        select x.UsersID
                    ).Contains(y.UserId)
            select y;                
            -- OR // select new { y.UserId, y.UserName};

SOURCE

答案 1 :(得分:0)

var query =
    from c in aspnet_Users 
    where !(from o in tbluser where o.active=="true" 
            select o.UserId)
           .Contains(c.UserId)
    select c;