Linq where clause is not in select statement

Can someone help me convert from SQL Query to LINQ VB.NET:

select rls.* from Roles rls(nolock)
where rls.id not in (
select r.ID from usersRole ur (nolock)
inner join Roles r(nolock) on ur.RoleID = r.ID
where user_id = 'NY1772')

      

thank

+2


source to share


2 answers


I find my own answer ...



     'construct a where ID list
     Dim lstRoleIDs = From ur In ctx.UsersRoles _
                      Join rl In ctx.Roles _
                      On ur.RoleID Equals rl.ID _
                      Where ur.User_ID = UserId _
                      Select rl.ID

     Dim newQ = (From r In ctx.Roles _
                 Where Not lstRoleIDs.Contains( _
                        r.ID) _
                 Select New UserRoleList With {.ID = r.ID, .PermDesc = r.ID & " - " & r.Permission & " - " & r.PermissionDescription})

      

+2


source


If you want to keep prompts (NOLOCK) I wrote a good solution using extension methods in C #. Note that this is the same as adding nolock hints to every table in the query.



0


source







All Articles