共用方式為


ObjectContext 建構函式 (String, String)

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

使用給定的連接字串 (Connection String) 和實體容器 (Container) 名稱,初始化 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 ( _
    connectionString As String, _
    defaultContainerName As String _
)
'用途
Dim connectionString As String 
Dim defaultContainerName As String 

Dim instance As New ObjectContext(connectionString, _
    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(
    string connectionString,
    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(
    String^ connectionString, 
    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 : 
        connectionString:string * 
        defaultContainerName:string -> ObjectContext
protected function ObjectContext(
    connectionString : String, 
    defaultContainerName : String
)

參數

  • connectionString
    類型:System.String
    連接字串,它也會提供中繼資料資訊的存取權。
  • defaultContainerName
    類型:System.String
    預設實體容器的名稱。 當您透過此方法設定 defaultContainerName 時,此屬性會變成唯讀的。

例外狀況

例外狀況 條件
ArgumentNullException

connectionString 是 null。

ArgumentException

connectionString、defaultContainerName 或中繼資料工作空間無效。

請參閱

參考

ObjectContext 類別

ObjectContext 多載

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