Linq query list contains a list

Are you trying to get a list of ObjectBs where all of the ObjectAs are in ListOfIdsA, or any of them?

I think you want either:

ListObjectB.Where(p => p.ListOfObjectA.Any(x => ListOfIdsA.Contains(x.Id)))

or

ListObjectB.Where(p => p.ListOfObjectA.All(x => ListOfIdsA.Contains(x.Id)))

(You may well want to make ListOfIdsA a HashSet<string> if it’s of significant size, btw.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)