1

Following up this post, I have a question to ask.

If I create the class:

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

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        ...
    }
}

That means I have to add all my business logic model domain classes into that DbContext or it is possible to add a second one?

Juan Salvador Portugal
  • 1,233
  • 4
  • 20
  • 38
  • Assuming you have already tried adding a second context, what problems did you encounter? – Martin Booth Feb 04 '14 at 00:01
  • You can create a second one with the same connection string name. It'll work. If you use Migrations, you'll have to enable migrations and run update database on them separately, however. – Anthony Chu Feb 04 '14 at 00:04

1 Answers1

2

It is possible to have another DbContext but the question is whether you want to. See Entity Framework: One Database, Multiple DbContexts. Is this a bad idea?

So in your case, if the entities in your domain model are separate from the IdentityDbContext then by all means create a new one for those entities. If they rely on anything from IdentityDbContext you will need to use that context for your domain entities. Otherwise you wouldn't be able to query across both.

Community
  • 1
  • 1
Kit
  • 20,354
  • 4
  • 60
  • 103