I have a list of ids:
var IdList = new int[]{1, 2};
I also have a list of users:
var userList = new List<User>()
{
new User() {Id = 1, Name = "User1" },
new User() {Id = 1, Name = "User2" },
new User() {Id = 2, Name = "User2" },
new User() {Id = 1, Name = "User3" },
new User() {Id = 1, Name = "User4" },
new User() {Id = 2, Name = "User4" }
};
I want to get a list of users that must contain all the Ids from the IdList. So in this example I want to return User2 and User4. I've seen other subset examples that are just using Except and return boolean and even when adapting to my needs do not produce the correct results. I also saw one marked as duplicate (Similar Question) which is trying to do exactly this but did not agree that it was a duplicate and was never truly answered. I have attempted:
userList.Where(u => IdList.All(i => i == u.Id)).ToList();
that will not return anything.