Reputation: 3451
If I have a database with multiple tables, but the every time I need to use a table in my website, I just add it to one model. Is it better to break up edmx files by functionality?
Upvotes: 2
Views: 781
Reputation: 12413
There is an argument that suggests that breaking up your site by splitting the EDMX into domain driven entities is a good idea. This enables you to setup a context with a view of the data specific to the job it will do, and isolating concerns. Julie Lerman goes into some detail in her Pluralsight course. Entity framework 1 large edmx or multiple domain driven models?'>I've also seen issues with this technique described here
Overall, the answer to whether this is a good idea probably depends on the nature of the database and the web application. If the DB contains data that should never be exposed to the web, then this sort of separation is essential. If on the other hand its just a handful of tables with no real issue to exposing them, its probably an additional complexity that's not required.
Upvotes: 2
Reputation: 45490
It really depends on your app structure, if all your entities are related then you should keep them in one single EDMX file.
You have to think EDMX as a class. So if you feel like they are better organized in a seperate file, then go ahead and create as many as you need to keep it organized/
I have done this in some of my application where I wanted to separate the concerns.
It just did not seem right for me to mix both Data Access Layer.
Something like this for admin:
private void SomeAdminFunction()
{
using (var db = new AdminEntities())
{
//Access all Admin entities
}
}
for users:
private void SomeUserFunction()
{
using (var db = new UserEntities())
{
//Access all User entities
}
}
Upvotes: 2