Malcolm
Malcolm

Reputation: 12864

Left join query using Linq2Sql

I have 3 tables called Users, Groups and UserGroups. UserGroups is the many 2 many join table.

I want to write a linq statement that gets me only those groups that DO NOT have a UserGroup record where UserID is say 1.

Please supply L2Q code if possible

Malcolm

Upvotes: 0

Views: 95

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500225

Well, you could express that as:

var query = db.Groups.Where(x => !db.UserGroups
                                    .Any(y => y.UserId == 1 && 
                                              y.GroupId == x.GroupId));

... assuming I've understood you correctly.

Upvotes: 1

Related Questions