Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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}))

Eg:

listOfGuids = {
    9c105700-98af-4c23-92ac-fd2dc5664b7a,
    7d6e0918-fb05-4b37-80f4-c7e5ccaa094d
}

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading