[英]Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>()); Error
Well the error I am getting is actually a compiler error which is 好吧,我得到的错误实际上是一个编译器错误,它是
CS0311: there is no implicit reference conversion from...
CS0311:没有来自...的隐式引用转换
I enabled migrations from package manager 我启用了来自程序包管理器的迁移
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" }
// );
//
}
}
And this statement: 这句话:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DbContext, Configuration>());
generates the following error: 产生以下错误:
Error 4 The type 'PMWeb.Migrations.Configuration' cannot be used as type parameter 'TMigrationsConfiguration' in the generic type or method 'System.Data.Entity.MigrateDatabaseToLatestVersion'.
错误4类型'PMWeb.Migrations.Configuration'不能用作通用类型或方法'System.Data.Entity.MigrateDatabaseToLatestVersion'中的类型参数'TMigrationsConfiguration'。 There is no implicit reference conversion from 'PMWeb.Migrations.Configuration' to 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
没有从“ PMWeb.Migrations.Configuration”到“ System.Data.Entity.Migrations.DbMigrationsConfiguration”的隐式引用转换。 f:\\dropbox\\partymag\\pmweb\\models\\pmdbcontext.cs 52 83 PMWeb
f:\\ dropbox \\ partymag \\ pmweb \\ models \\ pmdbcontext.cs 52 83 PMWeb
BTW, this was working fine before, I do not know what changed. 顺便说一句,之前运行良好,我不知道发生了什么变化。
Database.SetInitializer(new MigrateDatabaseToLatestVersion<PMDBContext, Configuration>());
I was supposed to give my context not the base context class. 我应该给我的上下文而不是基础上下文类。 Silly me.
傻我 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.