VS2013, EF6 code first, MVC, (VB)
I wanted to better understand the pros and cons of using either a single context, or splitting DbSets into multiple contexts. I have been reading through some of the old SO posts on multiple DbContexts and didn't really find what I was looking for; a comprehensive statement on when and where to use or not use multiple DbContexts.
In the case of a single user running a program such as Windows Forms on their own hardware, it would seem there is no reason to have multiple contexts for ease of working with the code.
In the case of a web application that runs a major business program for multiple businesses it would seem multiple DbContexts are essential for security and administration.
But I'd like to get confirmation if I'm thinking about this question correctly. All I can think of is the following, but then I'm quite new to this environment:
Pros of a single context:
- Coding only has a single context to deal with
- (Are there issues with relationships across contexts?)
- Migrations are easier because there is only one migration folder and process
- Easier to get a comprehensive diagram constructed in SSMS or EDMX
- (Link here for getting EDMX diagrams when using code first)
Cons of a single context:
- Security might be an issue for multiple web clients on an enterprise app
- (Is this an issue for simple websites that have simple memberships?)
- Some SO posts seem to suggest response time is an issue
- (What is the mechanism here?)
That's all I have. I don't know enough to fully understand the two sides, and given the different environments we can be working in, it would seem the answer to one or multiple contexts will be different.
I'm currently working on a website that will have memberships, and also a downloadable app which will be a personal app running on the user's hardware. In this case I think a single context for both makes sense, but before I get too deep into it, I though I would ask for some discussion on this. I presume others who are somewhat new to the environment will continue to have the same questions.
I also note that Microsoft saw fit to add multiple context capability to EF in EF6 and higher, so clearly there must be some programming environments that give rise to compelling reasons to have multiple contexts.
Thanks for the input.
Best Regards, Alan