简体   繁体   English

将复合类型从 postgresql 映射到 ef 核心

[英]Mapping composite types from postgresql to ef core

I defined the following composite type in my postgre db:我在 postgre db 中定义了以下复合类型

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

I have created a struct with the same properties:我创建了一个具有相同属性的结构:

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

And now I would like to use FooBar as such in an entity:现在我想在实体中使用 FooBar :

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

How would I configure ef core to map these properly?我将如何配置 ef core 以正确映射这些? Currently when trying to add something it will yield the following error:目前,当尝试添加一些东西时,它会产生以下错误:

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. System.InvalidOperationException:无法映射属性“Test.FooBar”,因为它属于“FooBar”类型,它不是受支持的原始类型或有效的实体类型。 Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.显式映射此属性,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略它。

Also the documentation for npgsql shows working examples without ef core. npgsql文档也显示了没有 ef 核心的工作示例。

Mapping to PostgreSQL composite types isn't yet supported, this is tracked by this issue .尚不支持映射到 PostgreSQL 复合类型,此问题对此进行了跟踪 Anyone interested, please go upvote it!有兴趣的小伙伴快点赞吧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM