I have an entity Advisor with a column of type jsonb.
[Column(TypeName = "jsonb")]
public ExpertiseArea ExpertiseArea { get; set; } = new();
public class ExpertiseArea
{
public List<TripCountry> TripCountries { get; set; } = new List<TripCountry>();
}
public class TripCountry
{
public int Id { get; set; }
public string Name { get; set; }
}
Assume the following LINQ query:
var query = query.Where(a
=> a.ExpertiseArea.TripCountries.Any(tc
=> queryParams.Directions.Contains(tc.Id)))
queryParams.Directions is an int[].
I want to select Advisor entities where ExpertiseArea.TripCountries contain each of queryParams.Directions int values.
Here is the JSON example:
{
"TripCountries": [
{ "Id": 3, "Name": "Austria" },
{ "Id": 83, "Name": "France" },
{ "Id": 6, "Name": "Poland" }
]
}
For example, queryParams.Directions is [3,6].
I want all the advisors with TripCountries having both Poland and Austria.
I tried to write it with EF.Functions but I'm not sure which exact function to use.
I tried to resolve it with ChatGPT, but it gives wrong answers only.
Any help appreciated.