Pregunta

Basado en un proyecto MVC5 de muestra que estoy tratando de aprender la forma correcta de manejar las migraciones.

En el directorio raíz, tengo una carpeta llamada "dbcontexts" con dos contextos.

Primero: IdentityContext.cs

    public class IdentityContext : IdentityDbContext<ApplicationUser>
{
    public IdentityContext()
        : base("DefaultConnection")
    { }
}

Luego, tengo una carpeta llamada IdentityMigrations con el 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" }
        //    );
        //
    }
}

Luego tengo MyContexts con propiedades similares.

Cuando intento ejecutar el comando "Actualizar-base de datos", obtengo este mensaje de error: 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'.

¿Alguna idea de cómo solucionar esta o una mejor manera de hacer esta cosa dbcontext?

¿Fue útil?

Solución

Sugerencia: Si solo está haciendo un proyecto de muestra para aprender las migraciones como usted dice, pegue a un DBContext.Manténgalo simple: fusiona a sus entidades en un DBContext que hereda desde IdentityDbContext<ApplicationUser>

Eliminar sus carpetas de migraciones existentes Ha creado - y re "Habilitar-migraciones" después de eliminar su segundo DBContext.Esto le ayudará a continuar aprendiendo las migraciones, en lugar de aprender a usar dos DBContext's en un proyecto.

Además, @Lajos, no estoy seguro de qué MVC está hablando, pero mi DBContext nunca ha heredado de DBMigrationsConfiguration: heredan de DBContext, o IdentityDbContext.Para lo que se refiere a la clase de migrationsconfiguration, que se genera al emitir "habilitaciones-migraciones" en un proyecto.Se utiliza para generar migraciones y sembrando datos.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top