有没有办法在实体框架 + PostgreSql 中使用数组 [英] Is there a way to use ARRAYs in Entity Framework + PostgreSql

查看:45
本文介绍了有没有办法在实体框架 + PostgreSql 中使用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将实体框架中的数组与 PostgreSql 一起使用?

Is it possible to use arrays in Entity Framework with PostgreSql?

假设,例如,我们有 POCO 类

Suppose, for instance, we had the POCO class

        public class MyTable
        {
            [Key]
            [Column("gid")]
            public int Gid { get; set; }
            [Column("name")]
            public string Name { get; set; }
            [Column("email")]
            public string Email { get; set; }
            [Column("somedata")]
            public int[] SomeData { get; set; }
        }

此时实体框架不会创建列somedata"并跳过它.有没有办法做到这一点?我的意思是不必使用单独的表格.Postgres 数组在您希望将少量或有限数量的值存储到单个列中时会派上用场.

At this point Entity Framework simply does not create the column "somedata" and skips it. Is there a way to do this anyway? And by that I mean not having to use a separate table. Postgres arrays come in handy at times where you want to store a small or limited number of values into a single column.

推荐答案

如果你使用 Entity 就可以做到这一点Framework CoreNpgsql EF Core provider.

代码优先的方法是:

[Column("somedata", TypeName = "integer[]")]
public int[] SomeData { get; set; }

这篇关于有没有办法在实体框架 + PostgreSql 中使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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