I'm attempting to do something easy, but I'm having trouble. With the use of EF6, I have two tables connected by a middle associative table, resulting in a many-to-many relationship:
I want to run a query on every user who is a part of a particular family. I thus receive a variety of families:
var db = new MyProjectEntities(); User user = GetUserById((int)HttpContext.Current.Session["CurrentUserId"]); var families = db.Users.Where(u => u.UserId == user.UserId).First().Families.ToArray();
Then, I want to ask everyone who is a member of these families:
var users = db.Users.Where(u => families.Contains(u.Families));
But I encounter this issue:
Argument for an instance: 'Database.Family' cannot be converted to 'System.Linq.IQueryable>'
I appreciate it.
You can employ any technique:
var users = db.Users.Where(u => u.Families.Any(fam => families.Contains(fam))).AsEnumerable();
I believe you are looking for this.