I have two IEnumerable lists.
I want to populate values into the second list based upon the results in the first.
The first IEnumerable list is populated like this:
IEnumerable<SelectListItem> selectedList =
CategoryServices.GetAttributesByCategoryID(categoryID); // it returns selected attributes for a particular category
I have a function to get all attributes. Now I want to get another list which contains all other attributes (ie, the items not present in selectedList). I tried this:
IEnumerable<SelectListItem> available =
CategoryServices.GetAllAttributes().Where(a => !selectedList.Contains(a));
But its not filtering. I am getting all attributes… Any ideas?
Make sure your
SelectListItemclass implementsIEquatable<SelectListItem>so theContains()method has a proper means for determining equality of instances.