日期:2014-05-20  浏览次数:20802 次

谁能帮我把这个sql语句改成linq的
select * from SysUserTbl
where ID in (select UserID from SysUserGroupGrantTbl where UserGroupID in (select UserGroupID from SysUserGroupGrantTbl where UserID = 83))

就是上面这个sql语句改成勇linq实现的,谢谢了

------解决方案--------------------
用Contains可以实现:

var query = 
from S in Context.SysUserTbl
where (from S1 in Context.SysUserGroupGrantTbl 
where (from S2 in Context.SysUserGroupGrantTbl 
where UserID = 83
select S2.UserGroupID 
).Contains(S1.UserGroupID)
select S1.UserID 
).Contains(S.ID) 
select S;
------解决方案--------------------
没有测试,也许有误

var sysuser=from su in SysUserTbl
join sugg in SysUserGroupGrantTbl on su.ID equals sugg.UserID
join sug in SysUserGroupGrantTbl on sugg.UserGroupID euals sug.UserGroupID
where sug.UserID=83
select su