Make EF use the local database in the App_Data folder

I use the POCO approach in all my projects using the Entity Framework. All this is good, but I have one problem: it creates a database on my SQL Express, instead I want it to store my database in a * .mdf file in the App_Data folder.

+6
source share
1 answer

Define the appropriate connection string in Web.config, which uses the AttachDBFilename keyword.

<connectionStrings> <add name="MyContextClassName" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=True;AttachDBFilename=|DataDirectory|MyDatabase.mdf;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> 
+6
source

All Articles