ObjectContext 构造函数 (EntityConnection, String)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 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 或元数据工作区无效。 |