Home > Software design >  EF Core array intersection
EF Core array intersection

Time:12-27

I use PostgreSQL and have a column codes of type text[], and I have another column filterCodes of type string[]. When I query data from the table, I need to check that codes contains at least one element from filterCodes, I try use Intersection and Any but neither seems to work.

How can I do this without writing custom functions?

patientQuery.Where(p => p.Codes.Intersect(filterCodes).Any());

CodePudding user response:

According to documentation Array Type Mapping (look at translation of array1 && array2)

It should be:

patientQuery = patientQuery
  .Where(p => p.Codes.Any(c => filterCodes.Contains(c)));
  • Related