Click here to Skip to main content
14,244,054 members
Rate this:
Please Sign up or sign in to vote.

I am quite new to MVC and EF. I created my MVC project and I selected single user authentication option while creating the project and visual studio has created the
public class ApplicationDbContext: IdentityDbContext<ApplicationUser>
. Then I created my own context to handle my business.

My question is: can I unify these 2 context classes in one context classes & how? So I can perform the migration on a single context instead of handles this for 2 classes

Thank You ALL.

What I have tried:

i do not know exactly what to do.
Updated 10-May-19 1:12am
Gerry Schmitz 9-May-19 19:19pm
Yep. You're picking up knowledge snippets and don't have the whole picture yet or how things evolve. see solution 1.
Rate this:
Please Sign up or sign in to vote.

Solution 1

There is a reason why they want you to create your own context and class to manage and handle your business logic.

Just imagine what will happen, if, Microsoft ships an update and that changes most of the code (if not all) from the IdentityDbContext<T> type. Can you afford such a build-breaking change? Because you are now having everything inside a single file, and that file can be easily changed by an update for the runtime/platform or package.

I could not handle the minor changes they made back in ASP.NET Core 1.1 to ASP.NET Core 2.0. I could not, and see this is what happened back then, Mission Impossible: Migrating .NET Core 1.x to 2.0[^].

That is why, I recommend keeping multiple contexts, there is no harm in it and for a normal more-than-personal project, there are usually multiple contexts, each handling its own purpose and connection to databases.

You are welcome to try, and share your experience here on CodeProject, I would like to read what happens! :)
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi Afzaal,

Thanks for the clarification. I just wanted to know the reason and best practices for this point. I am going to leave it as is and continue practicing on my project.

Thanks Again :)

