I’ve been working recently with Entity Framework 6. So far I find it pleasant enough, although not as intuitive (at least for me) as the likes of NHibernate.

One of the things I wanted to do was to determine the connection string in code, rather than specifying it in my web.config file. You can use the following code snippet to set your connection string.

1
2
3
4
5
6
7
public class MyContext : DbContext
{
public MyContext() : base()
{
Database.Connection.ConnectionString = myAlternateConnectionString;
}
}