共用方式為


EntityConnection 建構函式 (MetadataWorkspace, DbConnection)

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

使用指定的 MetadataWorkspaceDbConnection,初始化 EntityConnection 類別的新執行個體。

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

語法

'宣告
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification := "Object is in fact passed to property of the class and gets Disposed properly in the Dispose() method.")> _
Public Sub New ( _
    workspace As MetadataWorkspace, _
    connection As DbConnection _
)
'用途
Dim workspace As MetadataWorkspace 
Dim connection As DbConnection 

Dim instance As New EntityConnection(workspace, _
    connection)
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Object is in fact passed to property of the class and gets Disposed properly in the Dispose() method.")]
public EntityConnection(
    MetadataWorkspace workspace,
    DbConnection connection
)
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:DisposeObjectsBeforeLosingScope", Justification = L"Object is in fact passed to property of the class and gets Disposed properly in the Dispose() method.")]
public:
EntityConnection(
    MetadataWorkspace^ workspace, 
    DbConnection^ connection
)
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Object is in fact passed to property of the class and gets Disposed properly in the Dispose() method.")>]
new : 
        workspace:MetadataWorkspace * 
        connection:DbConnection -> EntityConnection
public function EntityConnection(
    workspace : MetadataWorkspace, 
    connection : DbConnection
)

參數

例外狀況

例外狀況 條件
ArgumentNullException

workspace 或 connection 參數為 null。

ArgumentException

工作空間中遺漏概念模型。-或-工作空間中遺漏對應檔案。-或-工作空間中遺漏儲存體模型。-或-連接不在已關閉狀態。

ProviderIncompatibleException

connection 不是來自於 ADO.NET Entity Framework 相容的提供者。

請參閱

參考

EntityConnection 類別

EntityConnection 多載

System.Data.Entity.Core.EntityClient 命名空間