EntityConnection 构造函数 (MetadataWorkspace, DbConnection)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]
使用指定的 MetadataWorkspace 和 DbConnection 来初始化 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
)
参数
- workspace
类型:System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace
与此 EntityConnection 关联的 MetadataWorkspace。
- connection
类型:System.Data.Common.DbConnection
此 EntityConnection 对象的基础数据源连接。
异常
例外 | 条件 |
---|---|
ArgumentNullException | workspace 或 connection 参数为 null。 |
ArgumentException | 工作区缺少概念模型。-或-工作区缺少映射文件。-或-工作区缺少存储模型。-或-连接未处于关闭状态。 |
ProviderIncompatibleException | connection 并非来自与 ADO.NET Entity Framework 兼容的提供程序。 |