Entity Framework - DbMigrator not executing migration classes

hoangyb

New Member
I have an issue executing migrations using DbMigrator, somehow the migration classes are not executed and of course doesn't reflect in the database.What I'm trying to implement is group my migrations to versions. Basically I have a Version base class in which all versions are derived from. For example I have a class Version1000 which corresponds to version 1.0.0.0.Version classes has a method called ExecuteMigrations which is responsible for executing migrations related to the version it corresponds.Here's a sample of a version class (Version1000 for 1.0.0.0), see the ExecuteMigrations method using DbMigrator, it also uses a VersionConfiguration class which derives from DbMigrationsConfiguration, it is in there where I set the namespaces, the directory, the ContextType.. etc..\[code\]public class Version1000 : Version{ public override string VersionNumber { get { return "1.0.0.0"; } } public static Version Version { get { return new Version1000(); } } public override void ExecuteMigrations() { var configuration = new VersionConfiguration(); configuration.TargetDatabase = new DbConnectionInfo(MyCustomContext.CONTEXT_CONNECTION_STRING_NAME); var migrator = new DbMigrator(configuration); migrator.Update(); }}\[/code\]VersionConfiguration Class\[code\]class VersionConfiguration : DbMigrationsConfiguration<MyCustomContext>{ public VersionConfiguration() { AutomaticMigrationsEnabled = false; MigrationsNamespace = "Some.Namespace._1000"; MigrationsDirectory = "Migration\\1000"; ContextType = typeof(MyCustomContext); } protected override void Seed(MyCustomContext context) { base.Seed(context); }}\[/code\]At application start of my application what I do is check the current version of my database and then apply versions which are not applied to the current database. This is done by calling the ExecuteMigrations method of the version class.The thing is I don't get any exceptions its just that the changes are not reflected to the database when the DbMigrator.Update method is called and the migration classes in the folder/namespace which is set in the DbMigrationsConfiguration where never executed.Application Type: ASP.NET MVC 4 .NET Framework: 4.5
 
Back
Top