Mafromedia
Mafromedia

Reputation: 21

Separate EDMX for grouping stored procedures

I have a complex database and would like to know if creating a separate edmx for stored procedures is a good route to take? My idea is to have multiple edmx files, based on the applications using the database. That way each application would have access only to the stored procedures it needed.

Upvotes: 2

Views: 80

Answers (2)

meda
meda

Reputation: 45500

I don't see why this would be a problem.

While @Khan might be right on some scenario, I believe if you project is large enough then you can, seperate them if it helps you stay organized.

I have done this in some of my application where I wanted to separate the concerns.

My solution had a admin project and a user project, I added a third one as a DLL which contained two EDMX. Then I added a reference to the same dll on both project.

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 Stored Procedures
    }
}

for users:

private void SomeUserFunction()
{
    using (var db = new UserEntities())
    {
          //Access all User Stored Procedures
    }
}

Upvotes: 1

Khan
Khan

Reputation: 18172

The following reasons NOT to separate EMDs come to mind

  1. If your procedures map to entities which you will be writing back to a database, you would be creating more work for yourself.
  2. Having 2 EDMs means having 2 choices of Context for what may not have a logical separation.
  3. Having 2 EDMs does not seem to appear cleaner in any way that I can think of.

Upvotes: 1

Related Questions