DbContext 建構函式 (DbConnection, Boolean)

[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]

使用現有的連接來連接資料庫,以建構新的內容執行個體。 如果 contextOwnsConnection 為 false,當處置此內容時,將不會處置此連接。

命名空間:  System.Data.Entity
組件:  EntityFramework (在 EntityFramework.dll 中)

語法

'宣告
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
Public Sub New ( _
    existingConnection As DbConnection, _
    contextOwnsConnection As Boolean _
)
'用途
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
)

參數

  • contextOwnsConnection
    類型:System.Boolean
    如果設定為 true,則處置內容時也會處置此連接,否則呼叫端必須處置此連接。

請參閱

參考

DbContext 類別

DbContext 多載

System.Data.Entity 命名空間