Connection String Reference from Class Constructor
When specifying a connection string property use the ‘name’ key word within contructure which instructs EF5 to throw an exception if it doesn’t find it. I would say this is better practice than not specifying the key word ‘name’.
public class ApplicationDB:DbContext
{
publicApplicationDB()
: base(“name=EF5.Demo“)
{}
}
Specifying a Connection Factory
You tell EF5 your using localdb by specifying it within your config file.
<entityFramework>
<defaultConnectionFactorytype=“System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework“>
<parameters>
<parametervalue=“v11.0“ />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Specifying a Connection string
AttachDbFileName should only be used during development.
DataDirectory is useful during development as it more eaily allows a team of developers to work on the one code base.
<connectionStrings>
<addname=“EF5.Demo” providerName=“System.Data.SqlClient” connectionString=“Data Source=(LocalDB)v11.0;AttachDbFileName=|DataDirectory|EF5.Demo.mdf;Integrated Security=True;MultipleActiveResultSets=True“ />
</connectionStrings>
I’ll also refer you to this useful post:
http://www.mssqltips.com/sqlservertip/2694/getting-started-with-sql-server-2012-express-localdb/