Database.SetInitializer(新的 MigrateDatabaseToLatestVersion<Context, Configuration>());错误
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>()); Error
好吧,我得到的错误实际上是编译器错误
CS0311: there is no implicit reference conversion from...
我从包管理器启用了迁移
public class Configuration : DbMigrationsConfiguration<PMDBContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
ContextKey = "Context.DB.Context";
}
protected override void Seed(PMWeb.Models.PMDBContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
并且这条语句:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DbContext, Configuration>());
生成以下错误:
Error 4 The type 'PMWeb.Migrations.Configuration' cannot be used as type parameter 'TMigrationsConfiguration' in the generic type or method 'System.Data.Entity.MigrateDatabaseToLatestVersion'. There is no implicit reference conversion from 'PMWeb.Migrations.Configuration' to 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. f:\dropbox\partymag\pmweb\models\pmdbcontext.cs 52 83 PMWeb
顺便说一句,这之前工作正常,我不知道发生了什么变化。
Database.SetInitializer(new MigrateDatabaseToLatestVersion<PMDBContext, Configuration>());
我应该提供我的上下文而不是基本上下文 class。傻我。 :)
好吧,我得到的错误实际上是编译器错误
CS0311: there is no implicit reference conversion from...
我从包管理器启用了迁移
public class Configuration : DbMigrationsConfiguration<PMDBContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
ContextKey = "Context.DB.Context";
}
protected override void Seed(PMWeb.Models.PMDBContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
并且这条语句:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DbContext, Configuration>());
生成以下错误:
Error 4 The type 'PMWeb.Migrations.Configuration' cannot be used as type parameter 'TMigrationsConfiguration' in the generic type or method 'System.Data.Entity.MigrateDatabaseToLatestVersion'. There is no implicit reference conversion from 'PMWeb.Migrations.Configuration' to 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. f:\dropbox\partymag\pmweb\models\pmdbcontext.cs 52 83 PMWeb
顺便说一句,这之前工作正常,我不知道发生了什么变化。
Database.SetInitializer(new MigrateDatabaseToLatestVersion<PMDBContext, Configuration>());
我应该提供我的上下文而不是基本上下文 class。傻我。 :)