Notes:
- Using Npsql.EntityFrameworkCore.PostgreSQL v3.1.4
- Using Npgsql v4.1.3.1
- Using Code-First approach
I have the following table (called Cars):

It has two columns:
- LicenseNumber (type text) (type string in Car.cs model)
- KitchenIntegrations (type jsonb) (type List in Car.cs) Where Integrations is a List of Integration type.
The Car class looks this:
public class Car
{
public string LicenseNumber {get;set;}
public List<Kitchen> KitchenIntegrations {get;set;}
}
Kitchen.cs looks like this:
public class Kitchen
{
public int Id {get;set;}
public string KitchenName {get;set;}
}
And finally my CarContext.cs looks like this:
public class CarContext : DbContext
{
public DbSet<Car> Cars { get; set; }
public CarContext()
{
}
public CarContext(DbContextOptions<CarContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("ConnectionStringGoesHere");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("public");
modelBuilder.Entity<Car>(
builder =>
{
builder.HasKey(i => i.LicenseNumber);
builder.Property(i => i.KitchenIntegrations).HasColumnType("jsonb").IsRequired(false);
}
);
}
}
In the Cars table I need to grab only the KitchenIntegration that has Id = 1.
I can do this easily in PSQL, but I am having issues when trying to query against a JSON Array.
I tried:
var integrations = context.Cars.Select(i => i.KitchenIntegrations.First(o => o.Id == 1)).ToList();
But get an issue where it can't be translated to SQL/PSQL.
So my question is how does one traverse an array or list of JSON in EntityFrameworkCore? (And if possible to only do it as server-side rather than client-side).
Thank you! Any help is greatly appreciated!