EntityConnection.GetMetadataWorkspace 方法
定义
重要
此 API 不符合 CLS。
返回与此 MetadataWorkspace 关联的 EntityConnection。Returns the MetadataWorkspace associated with this EntityConnection.
public:
System::Data::Metadata::Edm::MetadataWorkspace ^ GetMetadataWorkspace();
public System.Data.Metadata.Edm.MetadataWorkspace GetMetadataWorkspace ();
[System.CLSCompliant(false)]
public System.Data.Metadata.Edm.MetadataWorkspace GetMetadataWorkspace ();
member this.GetMetadataWorkspace : unit -> System.Data.Metadata.Edm.MetadataWorkspace
[<System.CLSCompliant(false)>]
member this.GetMetadataWorkspace : unit -> System.Data.Metadata.Edm.MetadataWorkspace
Public Function GetMetadataWorkspace () As MetadataWorkspace
返回
与此 MetadataWorkspace 关联的 EntityConnection。The MetadataWorkspace associated with this EntityConnection.
- 属性
例外
内联连接字符串包含一个无效的 Metadata 关键字值。The inline connection string contains an invalid Metadata keyword value.
注解
创建 MetadataWorkspace 类时,将自动创建 EntityConnection。A MetadataWorkspace is automatically created when the EntityConnection class is created. 创建过程可能引发特定元数据异常。The creation process might throw metadata-specific exceptions. 元数据将被加载到内存中,Entity Data Model (EDM) 应用程序则使用该元数据访问有关基础数据源的信息。Metadata is loaded into memory and an Entity Data Model (EDM) application uses that metadata to access information about the underlying data source. 有关详细信息,请参阅 ADO.NET Metadata。For more information, see ADO.NET Metadata.
为了避免无意使对象(如 System.Data.Common.CommandTrees 和 ObjectContext)与其元数据失去同步,EntityConnection 必须锁定对象的元数据。To avoid inadvertently putting objects such as System.Data.Common.CommandTrees and ObjectContext out of sync with their metadata, EntityConnection must lock its metadata. 锁定元数据后,不允许对连接字符串做出任何更改。No changes to the connection string are allowed after the metadata is locked. 下面是锁定元数据的两种方案:The following are two scenarios in which metadata is locked:
EntityConnection实例是通过无参数构造函数构造的,或是通过 EntityConnection(String) 接受连接字符串的构造函数构造的。The EntityConnection instance is constructed through the parameterless constructor, or through the EntityConnection(String) constructor, which accepts a connection string. 在任一情况下,连接字符串可能在打开连接前进行多次更改。In either case the connection string may be changed multiple times before the connection is opened. Open 或 GetMetadataWorkspace 锁定元数据。Open or GetMetadataWorkspace locks the metadata.
EntityConnection 实例通过 EntityConnection(MetadataWorkspace, DbConnection) 构造函数进行构造,此构造函数接受 MetadataWorkspace 和 DbConnection。The EntityConnection instance is constructed through the EntityConnection(MetadataWorkspace, DbConnection) constructor, which accepts a MetadataWorkspace and a DbConnection. 在这种情况下,元数据在构造时锁定。In this case the metadata is locked at construction time. 不允许对连接字符串做出任何更改。No changes to the connection string are ever allowed.
加载元数据后,EntityConnection 验证概念性模型、存储模型和映射文件是否全部存在。When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.