Created
January 4, 2014 16:59
-
-
Save kendallmiller/8257393 to your computer and use it in GitHub Desktop.
DbContext constructor override to accept a standard ADO.NET connection string. In this case RamsCore was the name of our EF context.
This file contains hidden or 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
| /// <summary> | |
| /// Create a new context with the specified named connection string from the application configuration | |
| /// </summary> | |
| /// <param name="connectionStringName"></param> | |
| public RamsCore(string connectionStringName) | |
| : base("name=RamsCore") | |
| { | |
| if (string.IsNullOrWhiteSpace(connectionStringName)) | |
| throw new ArgumentNullException("connectionStringName", "The name of a standard connection string in the config file must be supplied"); | |
| var configurationConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName]; | |
| if ((configurationConnectionString == null) || (string.IsNullOrWhiteSpace(configurationConnectionString.ConnectionString))) | |
| throw new InvalidOperationException("The connection string '" + connectionStringName + "' was not found in the configuration file or did not specify a connection string."); | |
| _connectionString = configurationConnectionString.ConnectionString; | |
| Database.Connection.ConnectionString = _connectionString; | |
| LoupeCommandInterceptor.Register(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment