1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

I personally use the same DbContext for use with Identity and other tables within my project. I think there would have to be a compelling reason to separate them, for example if you wanted to use the same User base for multiple projects. I'm just wondering what the rationale would be having them separate?
The Identity Context is mainly concerned about the user authentication, if you moved it to a data access project, you will have to add references to Microsoft.AspNet.Identity.Core and many other assemblies which has nothing to do inside a data access layer, this is why I keep it separate
You say that Identity has nothing to do with the data access layer, but doesn't it directly relate to the underlying data source and it's structure? Plus, if you're using Identity Framework, this is how you gain access to your user information?
Only the Microsoft.AspNet.Identity.EntityFramework is related to the data access layer, the rest of assemblies are not releated to Database as you can choose another way to store your users
It looks like Microsoft.AspNet.Identity.EntityFramework has a dependency on Microsoft.AspNet.Identity.Core
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.