I have 2 collections. 1 is an array of groupIds, and the other is an IEnumerable.
My user class contains another list of type IList, which denotes the groups the user belongs to:
public class User
{
public IList<Group> Groups { get; protected set; }
}
And the Group class looks something like this:
public class Group{
public long Group_Id { get; protected set; }
}
What I need to do is return a collection of all users who are in the groupIds array. I.e., I would want something like:
usersRepository.Where(user => user.Groups.Where(group => groupIds.Contains(group.id))
Such that if my groupIds array has group id of 5 and 6, all users in the useresRepository which belong to group 5 and 6 are returned.
So far, the best I've been able to come up with is the following:
UserRepo.Users.AsEnumerable().Where(user =>
user.GroupUsers.Where(wg => GroupIds.Contains(wg.Group_Id)));
But this is complaining since .Contains returns a boolean instead of my list, but I'm not sure how to fix that.
My code doesn't work due to .Contains() causing the expression to return a boolean rather than a collection. However, I'm not sure how else to check of the list of GroupIds nested within my User object contains the specified group ids.