Make your class name same as connection string name. It will work.
<add name="OdeToFoodDB2" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-OdeToFood-20140306003945;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-OdeToFood-20140306003945.mdf" providerName="System.Data.SqlClient" />
Update:
There are multiple ways in which you can tell the DbContext how to use a database server:
1.) Assuming you have connection string same as above, keep the context class name same as connection string name.
public class OdeToFoodDB2 : DbContext
{
}
2.) Alternatively, you can specify the connection string in context base constructor:
public class MyContext : DbContext
{
public MyContext()
: base("OdeToFoodDB2")
{
}
}
3.) Alternatively, you can also use the form “name=” for the string passed to the DbContext constructor. For example:
public class MyContext : DbContext
{
public MyContext()
: base("name=OdeToFoodDB2")
{
}
}