Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"dotnet ef database update" programatically with Entity Framework Core

I'd like to call these migrations from a script and while there's plenty of information on how to do that with Entity Framework standard there's very little with Entity Framework Core.

I believe that this is the command that I need but I'm not sure on how to instantiate it properly or where the underlying classes are.

https://github.com/aspnet/EntityFrameworkCore/blob/7c64310a66ad04d04c43edaa70dc9e3963cb493f/src/ef/Commands/DatabaseUpdateCommand.Configure.cs

Edit: There seems to be some confusion about what it is I'm trying to do. Here is an example in the standard Entity Framework. However, upon first look there doesn't seem to be equivilent to DbMigrator in entity framework core.

https://romiller.com/2012/02/09/running-scripting-migrations-from-code/

like image 653
Richard Vanbergen Avatar asked Dec 13 '22 16:12

Richard Vanbergen


1 Answers

We made it easier in EF Core:

using (var db = new MyDbContext())
{
    db.Database.Migrate();
}
like image 175
bricelam Avatar answered Jan 02 '23 17:01

bricelam