src/Shared/EntityFramework/Infrastructure/DbCompiledModel.cs
/// <summary>
/// Creates an instance of ObjectContext or class derived from ObjectContext.  Note that an instance
/// of DbContext can be created instead by using the appropriate DbContext constructor.
/// If a derived ObjectContext is used, then it must have a public constructor with a single
/// EntityConnection parameter.
/// The connection passed is used by the ObjectContext created, but is not owned by the context.  The caller
/// must dispose of the connection once the context has been disposed.
/// </summary>
/// <typeparam name="TContext"> The type of context to create. </typeparam>
/// <param name="existingConnection"> An existing connection to a database for use by the context. </param>
/// <returns>The context.</returns>
Creates an instance of ObjectContext or class derived from ObjectContext.  Note that an instance
of DbContext can be created instead by using the appropriate DbContext constructor.
If a derived ObjectContext is used, then it must have a public constructor with a single
EntityConnection parameter.
The connection passed is used by the ObjectContext created, but is not owned by the context.  The caller
must dispose of the connection once the context has been disposed.
Creates an instance of ObjectContext or class derived from ObjectContext . Note that an instance of DbContext can be created instead by using the appropriate DbContext constructor . If a derived ObjectContext is used then it must have a public constructor with a single EntityConnection parameter . The connection passed is used by the ObjectContext created but is not owned by the context . The caller must dispose of the connection once the context has been disposed .
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public TContext CreateObjectContext<TContext>(DbConnection existingConnection) where TContext : ObjectContext
        {
            Check.NotNull(existingConnection, "existingConnection");
            var metadataWorkspace = _workspace.GetMetadataWorkspace(existingConnection);
            var entityConnection = new EntityConnection(metadataWorkspace, existingConnection);
            var context = (TContext)GetConstructorDelegate<TContext>()(entityConnection);
            context.ContextOwnsConnection = true;
            if (String.IsNullOrEmpty(context.DefaultContainerName))
            {
                context.DefaultContainerName = _workspace.DefaultContainerName;
            }
            foreach (var assembly in _workspace.Assemblies)
            {
                context.MetadataWorkspace.LoadFromAssembly(assembly);
            }
            return context;
        }
[ SuppressMessage ( " " , " " ) ] public TContext CreateObjectContext < TContext > ( DbConnection existingConnection ) where TContext : ObjectContext { Check . NotNull ( existingConnection , " " ) ; var metadataWorkspace = _workspace . GetMetadataWorkspace ( existingConnection ) ; var entityConnection = new EntityConnection ( metadataWorkspace , existingConnection ) ; var context = ( TContext ) GetConstructorDelegate < TContext > ( ) ( entityConnection ) ; context . ContextOwnsConnection = true ; if ( String . IsNullOrEmpty ( context . DefaultContainerName ) ) { context . DefaultContainerName = _workspace . DefaultContainerName ; } foreach ( var assembly in _workspace . Assemblies ) { context . MetadataWorkspace . LoadFromAssembly ( assembly ) ; } return context ; }
Creates an instance of ObjectContext or class derived from ObjectContext.
Creates an instance of ObjectContext or class derived from ObjectContext .
// Set the DefaultContainerName if it is empty
None
existingConnection
DbConnection
An existing connection to a database for use by the context.
An existing connection to a database for use by the context .
typeparam
The type of context to create.
The type of context to create .