共用方式為


DbCompiledModel.CreateObjectContext<TContext> 方法

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

建立 ObjectContext 的執行個體或衍生自 ObjectContext 的類別。 請注意,可以改為使用適當的 DbContext 建構函式建立 DbContext 的執行個體。 如果使用衍生的 ObjectContext,它必須擁有包含單一 EntityConnection 參數的公用建構函式。 建立的 ObjectContext 會使用傳遞的連接,但是內容不會擁有此連接。 呼叫端必須在處置內容之後處置此連接。

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

語法

'宣告
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
Public Function CreateObjectContext(Of TContext As ObjectContext) ( _
    existingConnection As DbConnection _
) As TContext
'用途
Dim instance As DbCompiledModel 
Dim existingConnection As DbConnection 
Dim returnValue As TContext

returnValue = instance.CreateObjectContext(existingConnection)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public TContext CreateObjectContext<TContext>(
    DbConnection existingConnection
)
where TContext : ObjectContext
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
public:
generic<typename TContext>
where TContext : ObjectContext
TContext CreateObjectContext(
    DbConnection^ existingConnection
)
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
member CreateObjectContext : 
        existingConnection:DbConnection -> 'TContext  when 'TContext : ObjectContext
JScript does not support generic types and methods.

類型參數

  • TContext
    要建立之內容的類型。

參數

傳回值

類型:TContext
內容。

請參閱

參考

DbCompiledModel 類別

System.Data.Entity.Infrastructure 命名空間