gpt4 book ai didi

postgresql - NPGSQL 日期时间数组

转载 作者:行者123 更新时间:2023-11-29 13:45:12 26 4
gpt4 key购买 nike

我正在尝试将 Postgres 中的 timestamp[] 字段类型与 NPGSQL 一起使用,这样我就可以在我的 Entity Framework 模型中使用 DateTime[] 类型。

我已将其添加到我的 EF 代码优先模型中。

[Column("HostUnavailableDates", TypeName = "timestamp[]")]
public DateTime[] HostUnavailableDates { get; set; }

我已经创建了迁移并且数据库已成功更新。

但是,我在使用模型执行事务时遇到此错误。

Message: System.InvalidOperationException : The property 'HostApplication.HostUnavailableDates' could not be mapped, because it is of type 'DateTime[]' 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'.

我关注了this answer它不使用任何类型的属性忽略。除了我目前正在做的事情之外,我还需要为 DateTime 类型做些什么吗?

DateTime 实际上在这种情况下根本不被支持吗?

我正在使用 EF Core。

最佳答案

我假设您使用的是 Entity Framework 6.x。如果是这种情况,则根本不支持数组,您必须切换到 Entity Framework Core。

关于postgresql - NPGSQL 日期时间数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com