// <summary>
        // Creates a clone of the given <see cref="ObjectContext" />. The underlying <see cref="DbConnection" /> of
        // the context is also cloned and the given connection string is used for the connection string of
        // the cloned connection.
        // </summary>
        public ClonedObjectContext(
            ObjectContextProxy objectContext, 
            DbConnection connection,
            string connectionString, 
            bool transferLoadedAssemblies = true)
        {
            DebugCheck.NotNull(objectContext);
            // connectionString may be null when connection has been created from DbContextInfo using just a provider

            if (connection == null
                || connection.State != ConnectionState.Open)
            {
                connection =
                    DbProviderServices.GetProviderFactory(objectContext.Connection.StoreConnection).CreateConnection();
                DbInterception.Dispatch.Connection.SetConnectionString(
                    connection,
                    new DbConnectionPropertyInterceptionContext<string>().WithValue(connectionString));
                _connectionCloned = true;
            }

            _clonedEntityConnection = objectContext.Connection.CreateNew(connection);

            _objectContext = objectContext.CreateNew(_clonedEntityConnection);
            _objectContext.CopyContextOptions(objectContext);

            if (!String.IsNullOrWhiteSpace(objectContext.DefaultContainerName))
            {
                _objectContext.DefaultContainerName = objectContext.DefaultContainerName;
            }

            if (transferLoadedAssemblies)
            {
                TransferLoadedAssemblies(objectContext);
            }
        }
 public virtual ObjectContextProxy CreateNew(EntityConnectionProxy entityConnection)
 {
     return(new ObjectContextProxy(new ObjectContext(entityConnection)));
 }
 public virtual ObjectContextProxy CreateNew(EntityConnectionProxy entityConnection)
 {
     return new ObjectContextProxy(new ObjectContext(entityConnection));
 }