Change data source using MVC 3 Repository Pattern
Posted on 2011-10-11
I have been looking into the Repository pattern of coding data access for an MVC application. As I understand it, it allows me to change the database/data storage easily, but all the examples I've seen don't show how this is achieved.
I have my interface with the CRUD operations, I have the repository that implements the interface, and I have the data context set to a SQLce database.
This all works, but I want to be able to give the option to use a SQL Express database instead of the Compact Edition. How can I do that in my MVC app?
I would assume that I create another data context and use that in a new repository class the implements my interface, but how do I tell the MVC application to use this instead of the original via something like a web.config key?