-2

I want to change this sql statement into LINQ but i have i problem with IN clause

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
waka
  • 3,362
  • 9
  • 35
  • 54
Abdalla Omar
  • 75
  • 1
  • 10
  • 1
    What is the problem you are having ? what have you tried ? See: http://stackoverflow.com/questions/857973/linq-to-entities-sql-in-clause – Habib Jun 30 '15 at 14:35

1 Answers1

1

If I understood your question you want to retrieve all menus that belong to the role named "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);
Dejan Dular
  • 377
  • 1
  • 14