DbCompiledModel.CreateObjectContext<TContext>-Methode
[Diese Seite bezieht sich auf Entity Framework Version 6. Die neueste Version ist als 'Entity Framework' NuGet-Paket verfügbar. Weitere Informationen zu Entity Framework finden Sie unter msdn.com/data/ef.]
Erstellt eine Instanz von ObjectContext oder einer von ObjectContext abgeleiteten Klasse. Beachten Sie, dass stattdessen mit dem entsprechenden DbContext-Konstruktor eine Instanz von DbContext erstellt werden kann. Wenn ein abgeleiteter ObjectContext verwendet wird, muss er über einen öffentlichen Konstruktor mit einem einzelnen EntityConnection-Parameter verfügen. Die übergebene Verbindung wird vom ObjectContext verwendet, der Kontext ist jedoch nicht der Besitzer der Verbindung. Der Aufrufer muss die Verbindung verwerfen, sobald der Kontext verworfen wurde.
Namespace: System.Data.Entity.Infrastructure
Assembly: EntityFramework (in EntityFramework.dll)
Syntax
'Declaration
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
Public Function CreateObjectContext(Of TContext As ObjectContext) ( _
existingConnection As DbConnection _
) As TContext
'Usage
Dim instance As DbCompiledModel
Dim existingConnection As DbConnection
Dim returnValue As TContext
returnValue = instance.CreateObjectContext(existingConnection)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public TContext CreateObjectContext<TContext>(
DbConnection existingConnection
)
where TContext : ObjectContext
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
public:
generic<typename TContext>
where TContext : ObjectContext
TContext CreateObjectContext(
DbConnection^ existingConnection
)
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
member CreateObjectContext :
existingConnection:DbConnection -> 'TContext when 'TContext : ObjectContext
JScript does not support generic types and methods.
Typparameter
- TContext
Der Typ des zu erstellenden Kontexts.
Parameter
- existingConnection
Typ: System.Data.Common.DbConnection
Eine vorhandene Verbindung mit einer Datenbank für die Verwendung durch den Kontext.
Rückgabewert
Typ: TContext
Der Kontext.