샘플 MVC5 프로젝트를 기반으로 마이그레이션을 처리하는 올바른 방법을 배우려고합니다.동일한 데이터베이스에서 마이그레이션을 사용하기 위해 여러 DbContext 가져 오기
루트 디렉터리에 두 개의 컨텍스트가있는 "DbContexts"라는 폴더가 있습니다.
먼저 하나 IdentityContext.cs
public class IdentityContext : IdentityDbContext<ApplicationUser>
{
public IdentityContext()
: base("DefaultConnection")
{ }
}
는 내가 그럼 난 유사한 특성을 가진 MyContexts을 가지고있는 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" }
// );
//
}
}
와 IdentityMigrations라는 폴더가 있습니다. 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 물건을 할 수있는 더 좋은 방법 : 나는 "업데이트-데이터베이스"를 실행하려고하면
는 명령이 오류 메시지가?
그래, 기본 DbContext에 내 모델을 추가해도 괜찮습니까? 내가 본 모든 샘플은 ASP.NET ID를 기본값으로 유지하고 동일한 데이터베이스를 호출하는 자체 DbContext를 만들고 DbContexts를 모두 받아 들일 수 있도록 마이그레이션을 지시하는 문제가있었습니다. – Kaleet
네, 괜찮을 겁니다. 기본적으로 DbContext를 기본으로 제공하므로 필요에 따라 수정할 수 있지만 두 번째를 만들지 않아도됩니다. 나는 별개의 IdentityContext와 다른 컨텍스트를 사용하는 것에 대한 게시물을 보았지만 특정 시나리오를 다루지 않는 한 너무 복잡합니다. – Jack