Database.SetInitializer(new MigrateDatabaseToLatestVersion&l

本文关键字:MigrateDatabaseToLatestVersion new SetInitializer Database | 更新日期: 2023-09-27 17:57:04

好吧,我得到的错误实际上是编译器错误,即

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

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

Database.SetInitializer(new MigrateDatabaseToLatestVersion&l

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

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

相关文章:
  • 没有找到相关文章