I have this LINQ
var userGroups = this.ObjectContext.UserGroups.Include("Users");
The problem is that I have to filter “Users” if it is active by field IsActive.
So, I need to filter by filed of the including table “Users” where is IsActive.
How I can do it with LINQ?
Thank you!
____________
P.S.
I try to do the following but I am not sure…
var userGroups = this.ObjectContext.UserGroups;
foreach (var userGroup in userGroups )
{
var ussers = this.ObjectContext.Users.Where(f => f.UserGroupID == item.ID && f.IsActive == true).ToList<User>();
userGroup.Users = users;
}
Is this linq-to-entities? Then it is not possible to do any kind of filtering to the included entities that are eager loaded. Ladislav Mrnka wrote about it in his latest blog post.
It is of course possible to use linq-to-objects to handle the entities once loaded into memory, but if you only want a fraction of the available entities that would be inefficient.
A linq-to-objects solution: