Database.SetInitializer(new MigrateDatabaseToLatestVersion <context,configuration =“”>());错误

时间:2015-06-18 19:00:12

标签: c# entity-framework migration

我得到的错误实际上是编译错误

  

CS0311:来自...

没有隐式参考转换

我启用了从包管理器迁移

 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>()); 

生成以下错误:

  

错误4“PMWeb.Migrations.Configuration”类型不能用作泛型类型或方法“System.Data.Entity.MigrateDatabaseToLatestVersion”中的类型参数“TMigrationsConfiguration”。没有从'PMWeb.Migrations.Configuration'到'System.Data.Entity.Migrations.DbMigrationsConfiguration'的隐式引用转换。 f:\ dropbox \ partymag \ pmweb \ models \ pmdbcontext.cs 52 83 PMWeb

顺便说一句,这之前工作正常,我不知道发生了什么变化。

1 个答案:

答案 0 :(得分:1)

Database.SetInitializer(new MigrateDatabaseToLatestVersion<PMDBContext, Configuration>()); 

我应该给我的上下文而不是基本上下文类。傻我。 :)