/// <summary> /// Creates the database context for a connection to the specified server, /// by using a custom EDMX path and retrieving the other options from the backend configuration. /// </summary> /// <typeparam name="T">The ObjectContext type to create.</typeparam> /// <param name="edmxPath">The path to the .edmx-file. This path must be relative to the project. /// See <see cref="ContextCreationOptions.EdmxPath"/> for further information.</param> /// <returns>The created database context (derived from <see cref="ObjectContext"/>).</returns> public static T CreateContext <T>(string edmxPath) where T : ObjectContext { Assertions.AssertNotEmpty(edmxPath, "edmxPath"); ContextCreationOptions options = ContextCreationOptions.CreateFromSettings(); options.EdmxPath = edmxPath; return(CreateContext <T>(options)); }
/// <summary> /// Creates the <see cref="ContextCreationOptions"/> and uses the values from the backend configuration. /// </summary> /// <returns>An instance of <see cref="ContextCreationOptions"/> which uses the values from the backend configuration.</returns> public static ContextCreationOptions CreateFromSettings() { ContextCreationOptions options = new ContextCreationOptions(); options.HostName = ServiceFactory.BackendConfigurator.Get("Server.DB.HostName"); options.Port = int.Parse(ServiceFactory.BackendConfigurator.Get("Server.DB.Port")); options.UserId = ServiceFactory.BackendConfigurator.Get("Server.DB.UserId"); options.Password = ServiceFactory.BackendConfigurator.Get("Server.DB.Password"); options.DatabaseName = ServiceFactory.BackendConfigurator.Get("Server.DB.DatabaseName"); return options; }
/// <summary> /// Creates the <see cref="ContextCreationOptions"/> and uses the values from the backend configuration. /// </summary> /// <returns>An instance of <see cref="ContextCreationOptions"/> which uses the values from the backend configuration.</returns> public static ContextCreationOptions CreateFromSettings() { ContextCreationOptions options = new ContextCreationOptions(); options.HostName = ServiceFactory.BackendConfigurator.Get("Server.DB.HostName"); options.Port = int.Parse(ServiceFactory.BackendConfigurator.Get("Server.DB.Port")); options.UserId = ServiceFactory.BackendConfigurator.Get("Server.DB.UserId"); options.Password = ServiceFactory.BackendConfigurator.Get("Server.DB.Password"); options.DatabaseName = ServiceFactory.BackendConfigurator.Get("Server.DB.DatabaseName"); return(options); }
/// <summary> /// Creates the database context for a connection to the specified server. /// </summary> /// <typeparam name="T">The ObjectContext type to create.</typeparam> /// <param name="options">The options to use for connection.</param> /// <returns>The created database context (derived from <see cref="ObjectContext"/>).</returns> public static T CreateContext <T>(ContextCreationOptions options) where T : ObjectContext { Assertions.AssertNotNull(options, "options"); string connectionString = string.Format(ConnectionStringTemplate, options.EdmxPath, options.HostName, options.Port, options.UserId, options.Password, options.DatabaseName); return((T)Activator.CreateInstance(typeof(T), connectionString)); }