Mir
Mir

Reputation: 2539

Using Entity Framework with a Mirrored Database, and minimizing work duplication

Environment:
ASP.Net 4.0
MVC 4
SQL Server 2005
Visual Studio 2010

Issue:
We have an SQL 2005 Database which is transactionally replicated to a separate server because a number of large business queries are run against the data and slow the system down. The secondary server is used for all reports (read only), while the primary server is used for day-to-day business. Our legacy code uses stored procedures to access the database and it was relatively easy to maintain different connection strings and have all reports use the report server connection string. We've recently started writing all of our newer code using Entity Framework for data access, however, and I'm at a loss for how to deal with the two different servers.

A simple solution would be, perhaps, to simply maintain two .edmx and point all of the reports to the second .edmx. I strongly dislike this method, however, as it requires that the developers maintain the two different files.

Has anyone else encountered this scenario and devised a more appropriate solution? Is there any way I can use the same .edmx for both servers (since they are identical) but somehow specify at the Controller or Action level which connection string to use?

Ideally I am looking for a solution that does not require manual SSDL writing. I'd like to continue to use the designer and "Update Model from Database" features.

Thank you for your time, Mirzero

Upvotes: 2

Views: 1074

Answers (1)

TheRealTy
TheRealTy

Reputation: 2429

When creating the EntityContext object you can specify a connection string in the constructor. So you would just need to pass the required string to the method creating the EntityContext instance.

Upvotes: 2

Related Questions