[英]Npgsql.PostgresException: type "ltree" does not exist
I'm developing a WebAPI with asp.net core .net5.0]我正在开发一个带有 asp.net 核心 .net5.0 的 WebAPI]
In domain objects I've used Ltree
for hierarchy.在域对象中,我将Ltree
用于层次结构。 While adding and updating migration, getting followed error: Npgsql.PostgresException: type "ltree" does not exist
.添加和更新迁移时,出现以下错误: Npgsql.PostgresException: type "ltree" does not exist
。
I did some research and found that, If I run "create extension Ltree"
on PostgreSQL database, this will create extension for Ltree.我做了一些研究,发现如果我在 PostgreSQL 数据库上运行"create extension Ltree"
,这将为 Ltree 创建扩展。
In code first approach database will be created while adding and updating migrations, so I can not go to database and create an extension for that.在代码优先方法中,将在添加和更新迁移时创建数据库,因此我不能 go 到数据库并为其创建扩展。
My question is: is that possible creating an extension in migration?我的问题是:是否有可能在迁移中创建扩展?
public class Department
{
public int Id { get; set; }
[Column(TypeName = "Ltree")]
public string Ltree { get; set; }
public string Name { get; set; }
}
You can have EF Core create the extension for you by adding the following line in your model-building code (eg OnModelCreating):您可以通过在模型构建代码(例如 OnModelCreating)中添加以下行,让 EF Core 为您创建扩展:
modelBuilder.HasPostgresExtension("ltree");
Note that in version 7.0, the provider will automatically detect that an extension is needed (by going over your model properties), and will add the appropriate PostgreSQL extension without you having to do that explicitly (see https://github.com/npgsql/efcore.pg/issues/2137 ).请注意,在 7.0 版中,提供程序将自动检测是否需要扩展(通过检查您的 model 属性),并将添加适当的 PostgreSQL 扩展,而无需您明确地执行此操作(请参阅https://github.com/npgsql /efcore.pg/issues/2137 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.