将sql查询转换为linq

时间:2015-04-09 14:01:25

标签: sql linq

我有这个SQL查询:

select RoleID 
 from tblUserRole
 where UserID = 1
   and RoleID in 
       (Select ID from tblGreenRole 
        Where 
        IsFullAccess = 1) 

如何将此查询转换为linq?

1 个答案:

答案 0 :(得分:0)

这样的事情:

 var result = (from t1 in context.tblUserRole
 join t2 in context.tblGreenRole on t1.RoleID equals t2.ID
 where t1.UserID == 1 && t2.IsFullAccess == 1).ToList();

如果IsFullAccess的类型为bit,则更改为&& t2.IsFullAccess == true&& t2.IsFullAccess