Linq查询需要连接

时间:2015-08-18 08:57:11

标签: c# sql-server linq

我有两张桌子。我需要为第3组取消分配权限,我的SQL查询如下所示

选择权利名称     来自IB_Right_Master     其中id     不在(从IB_Group_Rights中选择RightID,其中GroupID =' 3');

Table : RightMaster

ID   |   RightName   |  RightGroupName       |
----------------------------------------------
1    |  Test1         |   test1              |
----------------------------------------------
2    |  Test2         |   test2              |
----------------------------------------------
3    |  Test3         |    Test3             |
----------------------------------------------
4    |  Test4         |   Group Test4        |
----------------------------------------------

表:Group Rgihts

ID   |   RightID     |      GroupID         |         
----------------------------------------------
1    |    1          |       1              |     
----------------------------------------------
2    |    1          |       2              |  
---------------------------------------------
3    |    2          |       3              | 
---------------------------------------------
4    |    3          |       4              | 
---------------------------------------------
5    |    1          |       3              |  
---------------------------------------------

所需输出:对于组ID 3

RightID   |   RightName     |            
----------------------------- 
3         |  Page Access    |      
------------------------------ 
4         |  Delete Group   |     
----------------------------- 

1 个答案:

答案 0 :(得分:1)

尝试此查询

from e in context.IB_Right_Master
where  !(from e2 in context.IB_Group_Rights
     where e2.GroupID == 3
     select e2.RightID).ToList().Contains(e.id)
select e;