Freigeben über


DbContext-Konstruktor (DbConnection, DbCompiledModel, Boolean)

[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 mithilfe der vorhandenen Verbindung zum Herstellen einer Verbindung mit einer Datenbank eine neue Kontextinstanz und initialisiert sie anhand des angegebenen Modells. Die Verbindung wird nicht verworfen, wenn der Kontext verworfen wird, wenn contextOwnsConnection den Wert false aufweist.

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
Public Sub New ( _
    existingConnection As DbConnection, _
    model As DbCompiledModel, _
    contextOwnsConnection As Boolean _
)
'Usage
Dim existingConnection As DbConnection 
Dim model As DbCompiledModel 
Dim contextOwnsConnection As Boolean 

Dim instance As New DbContext(existingConnection, _
    model, contextOwnsConnection)
[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public DbContext(
    DbConnection existingConnection,
    DbCompiledModel model,
    bool contextOwnsConnection
)
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
public:
DbContext(
    DbConnection^ existingConnection, 
    DbCompiledModel^ model, 
    bool contextOwnsConnection
)
[<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>]
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
new : 
        existingConnection:DbConnection * 
        model:DbCompiledModel * 
        contextOwnsConnection:bool -> DbContext
public function DbContext(
    existingConnection : DbConnection, 
    model : DbCompiledModel, 
    contextOwnsConnection : boolean
)

Parameter

  • contextOwnsConnection
    Typ: System.Boolean
    Mit true wird die Verbindung verworfen, wenn der Kontext verworfen wird, andernfalls muss der Aufrufer die Verbindung verwerfen.

Siehe auch

Verweis

DbContext Klasse

DbContext-Überladung

System.Data.Entity-Namespace