/// <summary> /// Returns the appropriate dynamic ObjectContext type. /// </summary> /// <typeparam name="T"> /// The ObjectContext type that the result type should derive from. /// </typeparam> /// <param name="entityConnectionString"> /// The entity connection string that references the metadata and identifies the /// persistent database. /// </param> /// <param name="persistent"> /// if set to <c>true</c> the ObjectContext uses a persistent database, otherwise /// transient. /// </param> /// <param name="dataLoader"> /// The data loader that initializes the state of the database. /// </param> /// <returns> /// The ObjectContext type. /// </returns> private static Type CreateType <T>( string entityConnectionString, bool persistent, IDataLoader dataLoader) where T : ObjectContext { EffortConnectionStringBuilder ecsb = new EffortConnectionStringBuilder(); if (dataLoader != null) { ecsb.DataLoaderType = dataLoader.GetType(); ecsb.DataLoaderArgument = dataLoader.Argument; } string effortConnectionString = ecsb.ConnectionString; return(ObjectContextTypeStore.GetObjectContextType( entityConnectionString, effortConnectionString, typeof(T), () => { if (string.IsNullOrEmpty(entityConnectionString)) { entityConnectionString = GetDefaultConnectionString <T>(); } return CreateType <T>( entityConnectionString, effortConnectionString, persistent); })); }
/// <summary> /// Creates a new EntityConnection instance that wraps an EffortConnection object /// with the specified connection string. /// </summary> /// <param name="entityConnectionString"> /// The entity connection string that references the metadata and identifies the /// persistent database. /// </param> /// <param name="effortConnectionString"> /// The effort connection string that is passed to the EffortConnection object. /// </param> /// <param name="persistent"> /// if set to <c>true</c> the ObjectContext uses a persistent database, otherwise /// transient. /// </param> /// <returns> /// The EntityConnection object. /// </returns> public static EntityConnection Create( string entityConnectionString, string effortConnectionString, bool persistent) { MetadataWorkspace metadata = GetEffortCompatibleMetadataWorkspace(ref entityConnectionString); EffortConnectionStringBuilder ecsb = new EffortConnectionStringBuilder(effortConnectionString); if (persistent) { ecsb.InstanceId = entityConnectionString; } else { ecsb.InstanceId = Guid.NewGuid().ToString(); } EffortConnection connection = new EffortConnection() { ConnectionString = ecsb.ConnectionString }; if (!persistent) { connection.MarkAsPrimaryTransient(); } return(CreateEntityConnection(metadata, connection)); }
public void EffortConnectionStringBuilder_IsTransient() { var writer = new EffortConnectionStringBuilder(); writer.IsTransient = true; var reader = new EffortConnectionStringBuilder(writer.ConnectionString); Assert.IsTrue(reader.IsTransient); }
public void EffortConnectionStringBuilder_DataLoaderType() { var writer = new EffortConnectionStringBuilder(); writer.DataLoaderType = typeof(Effort.DataLoaders.EmptyDataLoader); var reader = new EffortConnectionStringBuilder(writer.ConnectionString); Assert.AreEqual(typeof(Effort.DataLoaders.EmptyDataLoader), reader.DataLoaderType); }
public void EffortConnectionStringBuilder_DataLoaderArgument() { var writer = new EffortConnectionStringBuilder(); writer.DataLoaderArgument = "LoaderArgument"; var reader = new EffortConnectionStringBuilder(writer.ConnectionString); Assert.AreEqual("LoaderArgument", reader.DataLoaderArgument); }
public void EffortConnectionStringBuilder_InstanceId() { var writer = new EffortConnectionStringBuilder(); writer.InstanceId = "InstanceId"; var reader = new EffortConnectionStringBuilder(writer.ConnectionString); Assert.AreEqual("InstanceId", reader.InstanceId); }
public void CsvDataProvider() { string path = "C:\\"; DbConnection connection = DbConnectionFactory.CreateTransient(new CsvDataLoader(path)); EffortConnectionStringBuilder csb = new EffortConnectionStringBuilder(connection.ConnectionString); csb.DataLoaderType.Should().Be <CsvDataLoader>(); csb.DataLoaderArgument.Should().Be(path); }
public void EffortConnectionStringBuilder_Normalize() { var builder = new EffortConnectionStringBuilder(); builder.IsTransient = true; builder.Normalize(); Assert.IsFalse(builder.IsTransient); Guid value; Assert.IsTrue(Guid.TryParse(builder.InstanceId, out value)); }
public void transient_EffortConnection_should_normalize_connectionstring() { EffortConnection conn = new EffortConnection(); conn.ConnectionString = "IsTransient=True"; var builder = new EffortConnectionStringBuilder(conn.ConnectionString); // The IsTransient flag should be removed builder.IsTransient.Should().BeFalse(); Guid value; // The InstanceId should be set as a guid Guid.TryParse(builder.InstanceId, out value).Should().BeTrue(); }
/// <summary> /// Creates an EffortConnection object with a connection string that represents the /// specified parameter values. /// </summary> /// <param name="instanceId"> The instance id. </param> /// <param name="dataLoader"> The data loader. </param> /// <returns> The EffortConnection object. </returns> private static EffortConnection Create(string instanceId, IDataLoader dataLoader) { EffortProviderConfiguration.VerifyProvider(); EffortConnectionStringBuilder connectionString = new EffortConnectionStringBuilder(); connectionString.InstanceId = instanceId; if (dataLoader != null) { connectionString.DataLoaderType = dataLoader.GetType(); connectionString.DataLoaderArgument = dataLoader.Argument; } EffortConnection connection = new EffortConnection(); connection.ConnectionString = connectionString.ConnectionString; return(connection); }