Does Entity Framework use the default directory and what assumptions does it make?

I did (almost everything) everything right in the new EF project, but I forgot to use the named connection string in the EF context class, so it used the default value.

He created a new database in the default SQL Express data directory, and it worked just fine.

When I realized my mistake (after many years asking why the files do not appear in the app_data folder), I renamed the class to use the named connection string, and then I received the following error:

Unable to shut down. SqlConnection is not included specify the start directory.

I know how to fix it, but EF is like magic to me! I can’t believe that it works as well as he does, and I just wonder what it uses by default / is there a list of “assumptions” that EF uses on your behalf if you didn’t specify anything?

+3
source share
2 answers

By default, it uses a database with the same name as your context, but as soon as you specify a custom name string, you must specify the name of the database you are using either using the parameter Initial Catalogor Database.

+4
source

, , web.conf. .

web.conf:

add name="MovieDBContext"
   connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Movies.mdf;Initial Catalog=Movies;Integrated Security=SSPI;User Instance=true"
   providerName="System.Data.SqlClient"
+4

All Articles