将复合类型从 postgresql 映射到 ef core
Mapping composite types from postgresql to ef core
我在我的 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。感兴趣的小伙伴快点赞吧!
我在我的 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。感兴趣的小伙伴快点赞吧!