我有使用DbMigrator,不知何故迁移类不执行,当然在数据库中没有反映的问题执行迁移。实体框架 - DbMigrator不执行迁移类
我试图实现是一群我迁移到版本。基本上我有一个版本基类,其中所有版本都是从中派生的。
例如我有一个类Version1000其对应于1.0.0.0版本。
版本类有一个名为ExecuteMigrations方法负责执行与它对应的版本迁移。
下面是一个版本类(Version1000 for 1.0.0.0)的示例,请参阅使用DbMigrator的ExecuteMigrations方法,它也使用从DbMigrationsConfiguration派生的VersionConfiguration类,它在那里设置名称空间,目录,在ContextType。等等。
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();
}
}
VersionConfiguration类
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);
}
}
在我的应用程序的应用开始我做的是检查我的数据库的当前版本,然后适用的是无版本t应用于当前数据库。这是通过调用版本类的ExecuteMigrations方法来完成的。
事情是我没有得到任何异常,只是当调用DbMigrator.Update方法时,这些更改没有反映到数据库中,并且DbMigrationsConfiguration中设置的文件夹/命名空间中的迁移类从未执行。
应用类型:ASP.NET MVC 4 .NET框架:4.5
我有从DbMigration派生迁移类和是有在那里语句创建表就像在你的榜样。如果您试图查看自定义DBMigrationsConfiguration(VersionConfiguration),它将在其中设置迁移类的名称空间及其所在的文件夹,但不知何故它不会执行它们。 – mdcuesta 2013-03-18 07:40:55