I have a solution divided in 3 projects:
- Domain
- Web User Interface
- Unit tests
In my web.config, I defined my database like this:
<connectionStrings>
<add name="EntityFrameworkDbContext"
connectionString="Data Source=.\SQL2008;Initial Catalog=MvcLearning;Integrated Security=SSPI;Database=MVCLearning;AttachDBFilename=|DataDirectory|MVCLearning.mdf;MultipleActiveResultSets=True;User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
We have the |DataDirectory| used in my connectionstring.
Everything about the database should be located in the ‘domain’ projet, right? But when executing the solution for the first time, the database is created and I see that it is created in the WebUI\App_Data folder…
I thought it should be located in the App_Data in the ‘domain’ projet, shouldn’t?
Thanks.
Ideally it should be located in a data access layer which should be a separate layer of your application than your business/domain layer.
No, since the hosting project is the ASP.NET MVC application, things like App_Data are special folders which have only sense in a web application. So when you define
|DataDirectory|MVCLearning.mdfin the web.config of your web application that really means theApp_Datafolder of the web application.