我想将此sql语句更改为LINQ,但我有IN子句
的问题Declare @RoleId as nvarchar(128)
Set @RoleId = (SELECT Id FROM AspNetRoles WHERE Name = 'Admin')
SELECT * FROM Menus WHERE MenuEnable = 1
AND MenuParentId IS NULL
AND MenuId IN (SELECT MenuId FROM MenusRoles WHERE RoleId = @RoleId)
ORDER BY MenuOrder
答案 0 :(得分:1)
如果我理解了您的问题,您想要检索属于名为“Admin”的角色的所有菜单。
var results = (from m in Menus
join mr in MenuRoles on m.MenuId equals mr.MenuId
join anr in AspNetRoles on mr.RoleId equals anr.RoleId
where anr.Name == "Admin" && m.MenuParentId == null
orderby m.MenuOrder
select m);