Freigeben über


DbContext-Konstruktor (DbConnection, 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 eine neue Kontextinstanz mithilfe der vorhandenen Verbindung zum Herstellen einer Verbindung mit einer Datenbank. 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.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
Public Sub New ( _
    existingConnection As DbConnection, _
    contextOwnsConnection As Boolean _
)
'Usage
Dim existingConnection As DbConnection 
Dim contextOwnsConnection As Boolean 

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