DbContext 建構函式 (DbConnection, DbCompiledModel, Boolean)
[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]
使用現有的連接連接資料庫來建構新的內容執行個體,並從給定的模型將它初始化。 如果 contextOwnsConnection 為 false,當處置此內容時,將不會處置此連接。
命名空間: System.Data.Entity
組件: EntityFramework (在 EntityFramework.dll 中)
語法
'宣告
<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 _
)
'用途
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
)
參數
- existingConnection
類型:System.Data.Common.DbConnection
要用於新內容的現有連接。
- model
類型:System.Data.Entity.Infrastructure.DbCompiledModel
將會支援此內容的模型。
- contextOwnsConnection
類型:System.Boolean
如果設定為 true,則處置內容時也會處置此連接,否則呼叫端必須處置此連接。