public void Initialize() { this.connection = (EffortConnection)DbConnectionFactory.CreateTransient(); this.context = new FeatureDbContext( connection, CompiledModels.GetModel<RequiredFieldEntity>()); this.context.Configuration.ValidateOnSaveEnabled = false; }
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(); }
private static DbContainer GetDbContainer(DbConnection connection) { EffortConnection effortConnection = connection as EffortConnection; if (effortConnection == null) { throw new ArgumentException("", "connection"); } ////// Open if needed ////if (effortConnection.State == System.Data.ConnectionState.Closed) ////{ //// effortConnection.Open(); ////} return(effortConnection.DbContainer); }
/// <summary> /// Initializes a new instance of the <see cref="EffortTransaction" /> class. /// </summary> /// <param name="connection"> /// The <see cref="EffortTransaction" /> object. /// </param> /// <param name="isolationLevel"> /// The isolation level. /// </param> /// <exception cref="System.InvalidOperationException"> /// Ambient transaction is already set. /// </exception> public EffortTransaction( EffortConnection connection, System.Data.IsolationLevel isolationLevel) { if (System.Transactions.Transaction.Current != null) { throw new InvalidOperationException("Ambient transaction is already set."); } this.connection = connection; this.isolationLevel = isolationLevel; // Initialize new ambient transaction System.Transactions.TransactionOptions options = new System.Transactions.TransactionOptions(); options.IsolationLevel = TranslateIsolationLevel(isolationLevel); options.Timeout = new TimeSpan(0, 0, connection.ConnectionTimeout); this.systemTransaction = new System.Transactions.CommittableTransaction(options); this.transaction = NMemory.Transactions.Transaction.Create(this.systemTransaction); }
/// <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); }
/// <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; }