DbContext Constructor (DbConnection, DbCompiledModel, Boolean)

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Constructs a new context instance using the existing connection to connect to a database, and initializes it from the given model. The connection will not be disposed when the context is disposed if contextOwnsConnection is false.

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
)

Parameters

  • contextOwnsConnection
    Type: System.Boolean
    If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.

See Also

Reference

DbContext Class

DbContext Overload

System.Data.Entity Namespace