Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there Database Initializers in Entity Framework Core?

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?

like image 463
AxD Avatar asked Nov 02 '17 01:11

AxD


People also ask

Does EF core create database?

1 Creating a Database with Code First in EF Core. The Code First approach enables you to define an entity model in code, create a database from the model, and then add data to the database. MySQL Connector/NET is compatible with multiple versions of Entity Framework Core.

What databases does the Entity Framework core support?

EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.

Where is database SetInitializer?

The Database. SetInitializer() method should be kept before the Context object is initialized. In ASP.NET web application, the best place will be in Application_Start() event of Global. asax file.

What is the purpose of drop Create database always database initializer in Entity Framework?

DropCreateDatabaseAlways: As the name suggests, this initializer drops an existing database every time you run the application, irrespective of whether your model classes have changed or not.


1 Answers

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.

like image 200
P.Mar Avatar answered Sep 19 '22 15:09

P.Mar