Created
June 1, 2011 21:42
-
-
Save srn/1003401 to your computer and use it in GitHub Desktop.
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 OpenTrackerContext | |
{ | |
public static string ConnectionString = string.Empty; | |
private const string APP_CONFIG_KEY = "CONNECTIONSTRING"; | |
private const string EDMX_PATH = "OpenTrackerEntities"; | |
static OpenTrackerContext() | |
{ | |
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings[APP_CONFIG_KEY])) | |
throw new ConfigurationErrorsException(APP_CONFIG_KEY + " was not found in Application Settings"); | |
var conn = ConfigurationManager.AppSettings[APP_CONFIG_KEY]; | |
if (ConfigurationManager.ConnectionStrings[conn] == null) | |
throw new ConfigurationErrorsException(conn + " was not found in Connection Strings"); | |
var _connectionString = ConfigurationManager.ConnectionStrings[conn].ConnectionString; | |
if (string.IsNullOrEmpty(_connectionString)) | |
throw new ConfigurationErrorsException(conn + " cannot have an empty connection string"); | |
const string META_DATA = @"metadata=res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl;provider=MySql.Data.MySqlClient;provider connection string=""{1};Persist Security Info=True"""; | |
ConnectionString = string.Format(META_DATA, EDMX_PATH, _connectionString); | |
} | |
public OpenTrackerDbContext New() | |
{ | |
var context = new OpenTrackerDbContext(ConnectionString); | |
return context; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment