views:

73

answers:

2

I have the following two database tables. A group contains multiple members.

Groups: Id (int) | Name (int)

Members: Id (int) | GroupId (int) | IsExpert (bit)

I need to write a linq to sql query that returns the Groups that has no experts. Need some help

A: 
var GroupsWithNoExperts =
DBDataContext.Groups.Where(
    g=>!DBDataContext.Members.Any(m=>m.GroupID==g.Id && m.IsExpert
));
Andrew Barber
+1  A: 

Your answer should be those groups where the groups' collection of members doesn't contain any experts (ie !Any)

context.Groups.Where(group -> !group.Members.Any(member => member.IsExpert));
Kirk Broadhurst