I'm developing an application, and I need the connection string to be defined in the code itself, since there can not be the app.config file.
I'm developing an application, and I need the connection string to be defined in the code itself, since there can not be the app.config file.
To do this simply pass your connection string into the constructor of your context.
For example:
public class MeuDbContext: DbContext
{
public MeuDbContext(): base("Data Source=localhost;Initial Catalog=meudb;User Name=usuario;Password=senha;")
{
......
......
}
}
You can also do the same by passing DbConnection
, initializing it before passing it as a parameter.
I hope I have helped!