I want my .NET 7 app to boot up and create a database if one does not exist.
I am using Entity Framework Core.
There seems to be 2 conflicting methods:
Option #1:
context.Database.EnsureCreated()
I'm told this method will not work with database migrations, and it is difficult to add them to a database created this way later on. Seems to be popular. Maybe used for testing?
Option #2:
context.Database.Migrate()
This should just run your existing database migrations right?
All the professional app's I've been involved with used migrations, so it seems like this is the way to go.
Also, where do we add this code? Inside entity's DbContext
or inside Program.cs
?
Which option is better and what code would you use to implement it?
Thanks