A Sharaby
A Sharaby

Reputation: 15

get connectionstring from web config in class library data entity model

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

Upvotes: 1

Views: 1045

Answers (1)

Markus
Markus

Reputation: 22446

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.

Upvotes: 1

Related Questions