ObjectContext 建構函式 (EntityConnection, String)
[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]
使用給定的連接和實體容器名稱,初始化 ObjectContext 類別的新執行個體。
命名空間: System.Data.Entity.Core.Objects
組件: EntityFramework (在 EntityFramework.dll 中)
語法
'宣告
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification := "Class is internal and methods are made virtual for testing purposes only. They cannot be overrided by user.")> _
Protected Sub New ( _
connection As EntityConnection, _
defaultContainerName As String _
)
'用途
Dim connection As EntityConnection
Dim defaultContainerName As String
Dim instance As New ObjectContext(connection, _
defaultContainerName)
[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Class is internal and methods are made virtual for testing purposes only. They cannot be overrided by user.")]
protected ObjectContext(
EntityConnection connection,
string defaultContainerName
)
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA2214:DoNotCallOverridableMethodsInConstructors", Justification = L"Class is internal and methods are made virtual for testing purposes only. They cannot be overrided by user.")]
protected:
ObjectContext(
EntityConnection^ connection,
String^ defaultContainerName
)
[<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Class is internal and methods are made virtual for testing purposes only. They cannot be overrided by user.")>]
new :
connection:EntityConnection *
defaultContainerName:string -> ObjectContext
protected function ObjectContext(
connection : EntityConnection,
defaultContainerName : String
)
參數
- connection
類型:System.Data.Entity.Core.EntityClient.EntityConnection
EntityConnection,其中包含模型的參考與資料來源連接的參考。
- defaultContainerName
類型:System.String
預設實體容器的名稱。 當您透過此方法設定 defaultContainerName 時,此屬性會變成唯讀的。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentNullException | connection 是 null。 |
ArgumentException | connection、defaultContainerName 或中繼資料工作空間無效。 |