As already mentioned, you can declare your connection string inside the configuration file of your application with a name (for example, “YourDBName”), and then pass this to the base constructor of DbContext (I will add this in response to providing a complete answer - great answers already given to this).
Alternatively, you can set this programmatically in your DbContext Extension class using the Database.Connection.ConnectionString property. For example:
App.config:
<connectionStrings> <add name="YourDBName" connectionString="<Your connection string here>" providerName="<Your provider here>" /> </connectionStrings>
DatabaseContext.cs:
public class DatabaseContext : DbContext
Nick L. Feb 02 '17 at 17:56 on 2017-02-02 17:56
source share