c# - 将复合类型从 postgresql 映射到 ef core

标签 c# postgresql entity-framework-core npgsql composite-types

我在我的 postgre 数据库中定义了以下复合类型:

CREATE TYPE foobar AS
(
   foo NUMERIC,
   bar NUMERIC
);

我创建了一个具有相同属性的结构:

public struct FooBar
{
   public decimal Foo { get; set; }
   public decimal Bar { get; set; }
}

现在我想在实体中使用 FooBar:

public class FooyaEntity
{
   public Guid Id { get; set; }
   public string Name { get; set; }
   public FooBar FooBar { get; set; }
}

我将如何配置 ef core 以正确映射这些?目前在尝试添加内容时会产生以下错误:

System.InvalidOperationException: The property 'Test.FooBar' could not be mapped, because it is of type 'FooBar' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

还有 documentation for npgsql显示没有 ef 核心的工作示例。

最佳答案

还不支持映射到 PostgreSQL 复合类型,this is tracked by this issue .感兴趣的小伙伴快点赞吧!

关于c# - 将复合类型从 postgresql 映射到 ef core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59777160/

相关文章:

python - 无法在 centos 7 上安装 psycopg2

c# - 使用 EntityFramework Core 为包含大量信息的数据播种的最佳方法是什么?

c# - 在C#中读取一个xml元素并将元素的新值写回xml

c# - 给对象一个成员对象的独占锁

c# - 处理 400 万条记录时内存不足

c# - 是否可以在 Entity Framework Core 中创建基于字符串的 Include 替代方案?

c# - 抑制 EF 核心 3.0.x 初始化消息

c# - 没有实际解析的TryParse或任何其他具有性能优势的文本格式检查选项

用于在组内创建升序值的 SQL 查询

sql - 在 postgresql 的子查询中使用外部查询结果