有没有一种方法可以在实体框架+ PostgreSql中使用ARRAY [英] Is there a way to use ARRAYs in Entity Framework + PostgreSql
本文介绍了有没有一种方法可以在实体框架+ PostgreSql中使用ARRAY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在带有PostgreSql的Entity Framework中使用数组?
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; }
}
此时,Entity Framework根本不会创建 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.
推荐答案
如果您将实体框架核心与 Npgsql EF核心提供程序。
代码优先的方法是:
[Column("somedata", TypeName = "integer[]")]
public int[] SomeData { get; set; }
这篇关于有没有一种方法可以在实体框架+ PostgreSql中使用ARRAY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文