Setup Entity Framework For Dynamic Connection String

The generated TemplateEntities class is marked as partial.

All you have to do is add another file with another part of the partial class definition that exposes the constructor you want to use:

partial class TemplateEntities
{
  public TemplateEntities( string nameOrConnectionString )
    : base( nameOrConnectionString )
  {
  }
}

Then pass your connection string in to this constructor.

You want to put this code in a different file so it doesn’t get over-written when you update your edmx model.

Leave a Comment