Created
January 15, 2012 05:51
-
-
Save Lobstrosity/1614591 to your computer and use it in GitHub Desktop.
initialize DbContext with custom connection string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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