Question

I'm just putting myself through the paces learning MVC5 with EF6 and Code First and have run into some confusion...

How are people managing their DbSets with the Identity changes, especially with Migrations?

Are you managing two sets of Migrations or putting your normal DbSets into the IdentityModel.cs file?

This is what I have currently:

public class ApplicationUser : IdentityUser
{
}

public class AoecContext : IdentityDbContext
{
    public AoecContext()
        : base("DefaultConnection")
    {
    }
    public DbSet<Course> Courses { get; set; }
    public DbSet<Faculty> People { get; set; }
    public DbSet<SitePage> SitePages { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<SitePage>().HasOptional(p => p.CourseDetails);
    }
}

Is that a good idea, or just plain bad?

Was it helpful?

Solution

Your concerns are a bit better separated if you keep your IdentityDbContext separate from your DomainDbContext, but then you would need to manage two sets of migrations (among other things). As you have it you'll only need one set of migrations. I wouldn't consider what you're doing "bad" necessarily- it really depends on the project.

If its any consolation, the project that we are currently working on uses only one DbContext that also inherits from IdentityDbContext as yours does. It does pull in some references to the Data Access project that I wish weren't there, but it does greatly simplify working with EF in terms of database generation, persistence, and migrations. Whether we'll outgrow it in the future or not is hard to say.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top