Entity framework with connection string via code

2

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.

    
asked by anonymous 07.12.2014 / 17:10

1 answer

6

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!

    
07.12.2014 / 21:59