Skip to content

Instantly share code, notes, and snippets.

@Lobstrosity
Created January 15, 2012 05:51
Show Gist options
  • Save Lobstrosity/1614591 to your computer and use it in GitHub Desktop.
Save Lobstrosity/1614591 to your computer and use it in GitHub Desktop.
initialize DbContext with custom connection string
public class OurContext : DbContext
{
public string ClientKey { get; private set; }
/// We make use of the DbContext constructor overload that accepts a
/// connection string to connect to.
public OurContext(string clientKey)
: base(GetClientConnectionString(clientKey))
{
ClientKey = clientKey;
}
/// There's a static method in one of our base assemblies that returns a
/// client's database connection string based on the client's short name.
public static string GetClientConnectionString(string clientKey)
{
return AClassInOneOfOurBaseAssemblies.GetConnectionString(clientKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment