[SOLVED] Filter a list based on another list containing IEnumerable<Guid> using linq


I am looking for a way to filter a list based on another list that contains only the ids. If List A does not contain any of the ids in listOfGuids, get the filtered List that does not contain the ids

IEnumerable<Guid> listOfGuids = some list of Guid.
var filteredList = ListA.All(x=>listOfGuids.Where(x=>x.id!={all the items in list of Guid}))


listOfGuids = {

ListA =[
    {id="9c105700-98af-4c23-92ac-fd2dc5664b7a", name="abc"},
    {id="7d6e0918-fb05-4b37-80f4-c7e5ccaa094d", name="def"},
    {id="6fb0bcf3-9ca6-40c8-9fa1-f7557ef09558", name="ghi"}

Should return filteredList as

[{{id="6fb0bcf3-9ca6-40c8-9fa1-f7557ef09558", name = "ghi"}}]


You want items Where it’s not true that the list Contains the id:

var filteredList = ListA.Where(x => !listOfGuids.Contains(x.id))

Answered By – D Stanley

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *