EntityConnection.GetMetadataWorkspace Method ()


Returns the MetadataWorkspace associated with this EntityConnection.

This API is not CLS-compliant.

Namespace:   System.Data.EntityClient
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public MetadataWorkspace GetMetadataWorkspace()

Exception Condition

The inline connection string contains an invalid Metadata keyword value.

A MetadataWorkspace is automatically created when the EntityConnection class is created. The creation process might throw metadata-specific exceptions. Metadata is loaded into memory and an Entity Data Model (EDM) application uses that metadata to access information about the underlying data source. For more information, see ADO.NET Metadata.

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:

  • The EntityConnection instance is constructed through the default 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. M:System.Data.EntityClient.EntityConnection.Open() or M:System.Data.EntityClient.EntityConnection.GetMetadataWorkspace() locks the metadata.

  • 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.

When metadata is loaded, the EntityConnection verifies that the conceptual model, the storage model, and the mapping file are all present.

.NET Framework
Available since 3.5
Return to top