实体框架核心中是否有数据库初始化程序?

实体框架核心中是否有数据库初始化程序?

问题描述:

我找不到有关如何在EF Core中使用EF数据库初始化程序的示例,也找不到与EF Core一起发货的EF数据库初始化程序的列表。

I can't find examples on how to use EF Database Initializers with EF Core nor can I find a list of EF Database Initializers shipping with EF Core.

有数据库初始化程序的概念过时了吗?初始化数据库的当前方法是什么……或者不是初始化现有数据库的

Has the concept of Database Initializers become obsolete? What's the current approach of initializing a database ... or not initializing an existing database?

在.Net core中,您可以使用数据库属性形式的DbContext实例的功能。它允许您创建数据库(EnsureCreated),销毁数据库(EnsureDeleted)并迁移到上一次迁移(Migrate)。所需数据应放在迁移中。查看 https://docs.microsoft.com/ef/核心/管理方案/迁移/ 以获取更多详细信息。

In .Net core you can use functions of Database property form DbContext instance. It allows you to create database (EnsureCreated), destroy database (EnsureDeleted) and migrate to last migration (Migrate). Required data should be placed in migrations. Look at last section of https://docs.microsoft.com/ef/core/managing-schemas/migrations/ for more details.