【发布时间】:2014-01-29 23:38:06
【问题描述】:
基于示例 MVC5 项目,我正在尝试学习处理迁移的正确方法。
在根目录中,我有一个名为“DbContexts”的文件夹,其中包含两个上下文。
第一个:IdentityContext.cs
public class IdentityContext : IdentityDbContext<ApplicationUser>
{
public IdentityContext()
: base("DefaultConnection")
{ }
}
然后我有一个名为 IdentityMigrations 的文件夹,其中包含 Configuration.cs
internal sealed class Configuration : DbMigrationsConfiguration<TryFive.Web.DbContexts.IdentityContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
MigrationsDirectory = @"DbContexts\IdentityMigrations";
}
protected override void Seed(TryFive.Web.DbContexts.IdentityContext 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" }
// );
//
}
}
然后我有具有相似属性的 MyContexts。
当我尝试运行“更新数据库”命令时,我收到以下错误消息:The type 'TryFive.Web.DbContexts.IdentityContext' does not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
关于如何解决这个问题或更好的方法来做这个 DbContext 的任何想法?
【问题讨论】:
标签: c# entity-framework ef-code-first asp.net-mvc-5 entity-framework-migrations