小编use*_*870的帖子

如何查询 Npgsql.EntityFrameworkCore 中具有 JSON 数组的列

笔记:

  • 使用 Npsql.EntityFrameworkCore.PostgreSQL v3.1.4
  • 使用 Npgsql v4.1.3.1
  • 使用代码优先方法

我有下表(称为汽车): 在此输入图像描述

它有两列:

  • LicenseNumber(输入文本)(在 Car.cs 模型中输入字符串)
  • KitchenIntegrations(jsonb 类型)(Car.cs 中的列表类型)其中 Integrations 是集成类型的列表。

Car 类如下所示:

public class Car
{
   public string LicenseNumber {get;set;}

   public List<Kitchen> KitchenIntegrations {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

Kitchen.cs 看起来像这样:

public class Kitchen
{
   public int Id {get;set;}

   public string KitchenName {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

最后我的 CarContext.cs 如下所示:

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) …
Run Code Online (Sandbox Code Playgroud)

c# postgresql npgsql entity-framework-core jsonb

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

entity-framework-core ×1

jsonb ×1

npgsql ×1

postgresql ×1