I have an Entity Framework Project and a repository class in a separate project from my MVC3 web application. I have established a reference in my MVC project to the Entity Framework data project so i can instantiate an instance of the repository and call the methods thereof. However I get the error:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
I’ve run into this before and I believe the solution is to include the connection string from the entity framework app.config file in the MVC web.config file.
This doesn’t rest well with me. It feels like there should be another way that would make projects less tightly coupled together. I’m I dreaming or is there a better practice that would allow me just to make call to the referenced dll and be done with it?
Thanks
The
app.configfile that is included in the DLL of your Entity Framework project contains a Connection String that is used by the EDMX designer to find the target database when running an ‘Update Model from Database’ command.When deploying your application, the only configuration file that is known is the
web.config. Theapp.configfile from your EF dll is not used in production.So in your web.config you include the connection string that is used when you are running your MVC application. When using transformations you can also specify different connection strings for different deployment scenarios (test and production for example).
So it’s not like you are introducing some sort of coupling. You are just using the configuration methods that .NET offers you.