Bob5421
Bob5421

Reputation: 9183

Should i create a new DbContext object in MVC5 ASP.Net Project

I am creating a project with visual studio 2015. This project is created from asp.net project template (MVC checkbox is checked).

Multiple files are automatically generated (for user management for example). I have a file called IdentityModels.cs witch contain IdentityDbContext (for user tables).

I want to create other tables/entity for my application. Here is what i did: A created a second Context class, with inherits from DbContext.

But i am wondering if it is a good thing to have 2 DbContext for the same database. Should i put everything in IdentityDbContext ? Or create 2 databases for my project (one for authentification and the other for my own tables) ?

Thanks

Upvotes: 1

Views: 98

Answers (1)

Haitham Shaddad
Haitham Shaddad

Reputation: 4456

I suggest to leave the IdentityDBContext as is and create another data context in a separate class library project that represents your data access layer

When you run the migration you will specify the context name which be always the second one, once you get your identity tables created, you will not need the IdentityDBContext again for migration

Upvotes: 1

Related Questions