views:

23

answers:

1

My ASP.NET MVC 2 application uses Entity Framework 4.0 for the data model. Following the instructions on http://blogs.msdn.com/b/aspnetue/archive/2010/09/17/second_2d00_post.aspx I put the .edmx in its own assembly so my solution has two projects:

MyApp.Core (ASP.NET MVC 2 Web Application Project, references MyApp.DataLayer)
 Models/
 Controllers/
 Views/
 Web.config

MyApp.DataLayer (Class Library Project)
 Entities.edmx
 App.Config (<-- generated by edmx when I update model from DB)

When I regenerate Entities.edmx, it creates the App.Config file under MyApp.DataLayer with connection strings to the database. The problem is that when I deploy the solution, the Web.config is the only config also deployed, so I have to manually add these connection strings to it otherwise I get an exception at runtime because they cannot be found.

I'd like to not the same connection string defined in both Web.config and App.Config. How should I organize my projects/config files such that the connection string to the db are found in only one place? Is this possible?

+1  A: 

You can either embed the autogenerated app.config in your Model project and reference the connection string when you create your DataContext using GetEmbeddedResource...or (the more normal approach) copy the connection strings manually from the auto-generated app.config to your web.config.

If you want to be really ingenuitive, create a simple T4 template that copies the app.config connection strings in your web.config when you generate the EDMX model.

JeffN825

related questions