Is there a way for code in my ASP.NET MVC 4, code-first EF app to retrieve the current migration name? I want to display the migration name on an administrator's status page just as a sanity check to verify that the expected migration(s) have been applied.
Asked
Active
Viewed 575 times
1 Answers
0
You can use the DbMigrator (DbMigrator) class for that.
e.g.
var migrator = new DbMigrator(_configuration);
var pending = migrator.GetPendingMigrations();
var all = migrator.GetLocalMigrations();
Where _configuration is your Configuration class under the Migraiton dir.
You need to experiment a bit - see which actually fits your bill.
Also, I'm suggesting that you make an 'initializer' instead of just adding that into the code. As that's how it's usually done, and a 'natural spot' for those things to happen (you don't 'call it', it 'calls you').
Check this link for an implementation of a custom initializer - which includes some DbMigrator code.
How to create initializer to create and migrate mysql database?
Community
- 1
- 1
NSGaga-mostly-inactive
- 13,682
- 3
- 39
- 50