How to specify database name in Code First?

Solution 1:

Create a connection string in the app.config/web.config with the same name as the context and the EF will use that DB.

Solution 2:

How to Use a Different Connection String Name with EF

EF will use the name of the database in the connection string. When you want to decouple the name of your connection string from EF, you need to provide your connection string to the constructor. Example:

public class DatabaseContext : DbContext
{
    public DatabaseContext() 
      : base(ApplicationParameters.ConnectionStringName)
    {
    }

    public DatabaseContext(string connectionStringName)
      : base(connectionStringName)
    {
    }

}

Solution 3:

in Class :

public class Context : DbContext
{
    //SET CONNECTION STRING NAME FOR DataBase Name :
    public Context() : base("YourConnectionName") { }

    public DbSet<Category> Categories { get; set; }
    public DbSet<Product> Products { get; set; }
}

in web.config:

<connectionStrings>  
    <add name="YourConnectionName" connectionString="Data Source=A-PC\SQLEXPRESS;
    Initial Catalog=MyDataBase; Integrated Security=True" 
    providerName="System.Data.SqlClient" />
</connectionStrings>  

Thanks ferventcoder.
Ref => http://brandonclapp.com/connection-strings-with-entity-framework-5-code-first/