Npgsql中如何处理text []数组字段类型? [英] How to deal with a text[] array field type in Npgsql?

查看:196
本文介绍了Npgsql中如何处理text []数组字段类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有单个表的Postgres 12数据库:

I have a Postgres 12 database with a single table:

CREATE TABLE public.messages
(
    sender text COLLATE pg_catalog."default",
    "timestamp" timestamp with time zone,
    message_id bigint,
    text text COLLATE pg_catalog."default",
    priority bigint,
    parameters text[] COLLATE pg_catalog."default"
)

现在,当我想通过右键单击项目在满足条件的.NET Winforms(而非.NET Core)应用程序中使用此表时,从数据库中添加新项,ADO.NET实体数据模型,EF代码,配置我的连接(成功的连接测试),选择我的表,出现此错误:

Now, when I want to use this table in met .NET Winforms (not .NET Core) application by right-clicking the project, add new item, ADO.NET Entitity Data Model, EF Code First from Database, configuring my connection (successful connection test), choosing my table, I get this error:

严重性代码描述项目文件行抑制状态 警告错误6005:当前不支持数据类型"_text" 目标实体框架版本;列中的参数" 表"test.public.messages"是 排除在外. LogTest D:\ Projekte \ LogTest \ Model1.cs 1

Severity Code Description Project File Line Suppression State Warning Error 6005: The data type '_text' is currently not supported for the target Entity Framework version; the column 'parameters' in the table 'test.public.messages' was excluded. LogTest D:\Projekte\LogTest\Model1.cs 1

parameters字段没有进入消息类:

The parameters field did not make it into the messages class:

[Table("public.messages")]
public partial class message
{
    public long id { get; set; }
    public string sender { get; set; }
    public DateTimeOffset? timestamp { get; set; }
    public long? base_message_id { get; set; }
    public string text { get; set; }
    public long? priority { get; set; }
}

除了parameters之外,该模型还可以工作,我可以从数据库中获取数据.当我尝试手动添加属性时,它仍然运行,但是参数始终为null:

Apart from parameters, the model works and I can get data from the DB. When I try to add the property manually, it still runs, but parameters is always null:

    public string[] parameters { get; set; } // also tried List<string>

我如何使其起作用?根据我在阅读文档时所了解的内容,我认为应该可以吗?

How can I make it work? From what I understand when reading the docs, I think it should be possible?

我的应用程序针对.NET Framework 4.6,我正在使用EntityFramework6.Npgsql版本6.4.1.0和Npgsql版本4.0.10.0.

My application is targetting .NET Framework 4.6, I'm using EntityFramework6.Npgsql version 6.4.1.0 with Npgsql version 4.0.10.0.

推荐答案

映射数组不支持EF6,并且可能永远不会支持-EF6的类型模型非常封闭/受限制,并且不允许公开特定于数据库的类型(尤其是不复杂的情况,例如数组).

Mapping arrays is not supporting in EF6, and will probably never be - EF6's type model is very closed/restricted, and doesn't allow for exposing database-specific types (and especially not complicated cases like arrays).

EF Core提供程序确实对PostgreSQL数组提供了很好的支持,如果它们对您的工作很重要,我建议您考虑使用Core.

The EF Core provider does have pretty good support for PostgreSQL arrays, if they're central to what you're doing I'd suggest considering Core instead.

这篇关于Npgsql中如何处理text []数组字段类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆