Share via


DbCompiledModel.CreateObjectContext<TContext>(DbConnection) Method

Definition

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.

public TContext CreateObjectContext<TContext> (System.Data.Common.DbConnection existingConnection) where TContext : System.Data.Entity.Core.Objects.ObjectContext;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public TContext CreateObjectContext<TContext> (System.Data.Common.DbConnection existingConnection) where TContext : System.Data.Entity.Core.Objects.ObjectContext;
member this.CreateObjectContext : System.Data.Common.DbConnection -> 'Context (requires 'Context :> System.Data.Entity.Core.Objects.ObjectContext)
Public Function CreateObjectContext(Of TContext As ObjectContext) (existingConnection As DbConnection) As TContext

Type Parameters

TContext

The type of context to create.

Parameters

existingConnection
DbConnection

An existing connection to a database for use by the context.

Returns

TContext

The context.

Attributes

Applies to