0

I am trying to find a way to have my Entity Framework model in a seperate project within my ASP.NET solution.

Currently I have my DataManager project (which contains my EF model and some classes) and a second project which contains all my web project files.

The problem that I have come across is that I have a database connection string in a App.Config file in my DataManager project and the same connection string in my Web.Config from my web project. I basically have a duplicate connection string.

Is there a way to only use only one connection string in my project (preferably from my web.config)?

My only concern is that when it comes to compiling my project I will not be able to change the connection string in the App.Config contained in my DataManager project.

I would be grateful if someone could help me in the correct way of having a seperate project to contain my EF model. Or suggestions on better ways.

Many Thanks!

R100
  • 471
  • 1
  • 10
  • 25

1 Answers1

0

In my project I have my EF in a domain layer and my UI in a seperate layer. The UI contains the webconfig file which in turn has the connection string that EF uses. So yes it's completely acheivable. My webconfig will superseed the app.config setting.

My suggestion it terms of layering your app would be to look at some DDD. I'm using EF4 in conjuction with MVC and the repository pattern, which seems an elegant fit. I'm not saying you need to use MVC, but it's certainly worth looking at having a domain layer for ef4.

This is the application I've used as my guide. Note this is based around mvc, but the domain aspect could be true of any application http://mvcsamples.codeplex.com/

hoakey
  • 998
  • 3
  • 18
  • 34
  • Ah great! Thats good to know my web.config will superseed the app.config! The MVC example looks like a good choice to use in my next project. And for that you get a tick! :-) – R100 Nov 29 '10 at 11:53
  • 1
    Glad to help. I was basically where you are about 2 months ago. Here are the things that I would recommend looking into as a result. MVC2, EF4, POCO, Repository Pattern, Dependancy Injection. All of these are pretty simple after a little reading. But certainly look to use POCO with your EF model. You can pecify to generate them when building your EF model. Some good links http://daveswersky.com/2010/05/26/entity-framework-4-then-and-now/ http://stackoverflow.com/questions/3478964/ef-4-with-poco-in-class-library-as-mvc-2-model/3479126#3479126 – hoakey Nov 29 '10 at 12:01