1

i have main three layers in my solution :

1-Business layer : contains business requirements (interfaces,business models)

2-Data Access Layer : which implement Business layer interfaces and write or read from my database and i use entity framework for this

3-Web layer which is MVC web project which has reference of business layer and data access layer

all i want is to add entity data model in data access layer using the same connection string of my web.config project and i can't find a simple way for that

4
  • The web.config should contain a connection string that the context picks up automatically. If this doesn't happen you should give some more details like how you instantiate contexts and what the current connection string looks like. Commented Apr 18, 2014 at 19:33
  • yes my web.config contains the connectionstring Commented Apr 18, 2014 at 21:31
  • That's not what I meant by "more details". Commented Apr 18, 2014 at 21:34
  • my web.config contains the connection string information and if i add the entity data model to the class library it creats its own connection string in the app.config. and i don't wanna that way. Commented Apr 18, 2014 at 21:53

1 Answer 1

1

Instead of having the data layer use a connection string from the web frontend, rather configure the connection string that the data layer needs in the web.config. Otherwise you introduce a dependency from the data layer to the web layer - something that you most likely do not want.

Therefore I'd suggest to create the entity model in the data layer and copy the connection string from the app.config of the class library to the web.config so that it is also used when running/deploying the application. In case you want to use different connections for different environemnts, you can use web.config transformations to use the correct connection string when deploying to a specific environment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.