4
votes

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/

1
Do you mean running Update-Database from Package Manager Console? - vivek nuna
No. I mean calling it from a script I wrote myself. Not from the CLI. - Richard Vanbergen
Do you mean run pending migrations in Startup? - Brad
Please see my edit. - Richard Vanbergen

1 Answers

10
votes

We made it easier in EF Core:

using (var db = new MyDbContext())
{
    db.Database.Migrate();
}