Export (0) Print
Expand All

EntityContainer Class

Represents an entity container in a conceptual model. An EntityContainer is a logical grouping of entity sets and association sets.

Namespace:  System.Data.Metadata.Edm
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

'Declaration
Public NotInheritable Class EntityContainer _
	Inherits GlobalItem

The EntityContainer type exposes the following members.

  NameDescription
Public propertyBaseEntitySetsGets a list of entity sets and association sets that this EntityContainer includes.
Public propertyBuiltInTypeKindGets the built-in type kind for this EntityContainer. (Overrides MetadataItem.BuiltInTypeKind.)
Public propertyDocumentationGets or sets the documentation associated with this type. (Inherited from MetadataItem.)
Public propertyFunctionImportsSpecifies a collection of EdmFunction elements. Each function contains the details of a stored procedure that exists in the database or equivalent CommandText that is mapped to an entity and its properties.
Public propertyMetadataPropertiesGets the list of properties of the current type. (Inherited from MetadataItem.)
Public propertyNameGets the name of this EntityContainer.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEntitySetByNameReturns an EntitySet object by using the specified name for the entity set.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetRelationshipSetByNameReturns a RelationshipSet object by using the specified name for the relationship set.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns the name of this EntityContainer. (Overrides Object.ToString.)
Public methodTryGetEntitySetByNameReturns an EntitySet object by using the specified name for the entity set.
Public methodTryGetRelationshipSetByNameReturns a RelationshipSet object by using the specified name for the relationship set.
Top

On the conceptual level, the EntityContainer class represents a container that will be mapped to a database object in the storage metadata schema. In the storage level, the EntityContainer class represents a description of the table and/or key relationships that persist data for applications built on the model. For more information about the entity containers in a conceptual model, see Entity Containers (EDM).

The following code sample demonstrates how to get a metadata workspace from the connection and then use that metadata workspace to retrieve information about the entity containers in the specified data model. Note that the metadata workspace is a runtime service component that provides support for retrieving metadata.

The code sample uses a CSpace and a SSpace to specify the model. The CSpace represents the default name for the conceptual model. The SSpace represents the default name for the storage model.

The GetEntityContainers method gets a collection of entity containers and then iterates through the collection to get each entity set and association set in the specified container. The code sample uses the AdventureWorks Model that is provided in the Adventure Works Model (EDM)topic. For an example of the application config file, see Adventure Works Object Model in Applications (EDM).

Imports System
Imports System.Collections.ObjectModel
Imports System.Data
Imports System.Data.EntityClient
Imports System.Data.Metadata.Edm

Class GetEntityContainerExample
  Public Shared Sub Main()
    Try
      ' Establish a connection to the underlying data provider by 
      ' using the connection string specified in the config file.
      Using connection As EntityConnection = _
        New EntityConnection("Name=AdventureWorksEntities")

        ' Open the conection.
        connection.Open()

        ' Access the metadata workspace.
        Dim workspace As MetadataWorkspace = _
           connection.GetMetadataWorkspace

        ' Get the entity containers in the conceptual model.
        GetEntityContainers(workspace, DataSpace.CSpace)

        ' Get the entity containers in the storage model.
        GetEntityContainers(workspace, DataSpace.SSpace)
      End Using
    Catch exceptionMetadata As MetadataException
       Console.WriteLine("MetadataException: {0}", _
          exceptionMetadata.Message)
    Catch exceptionMapping As MappingException
       Console.WriteLine("MappingException: {0}", _
          exceptionMapping.Message)
     End Try
  End Sub

  Public Shared Sub GetEntityContainers( _
    ByVal workspace As MetadataWorkspace, ByVal model As DataSpace)

    ' Get a collection of the entity containers.
    Dim containers As ReadOnlyCollection(Of EntityContainer) = _
       workspace.GetItems(Of EntityContainer)(model)

    ' Iterate through the collection to get each entity container.
    Dim container As EntityContainer
    For Each container In containers
      Console.WriteLine("EntityContainer Name: {0} ", container.Name)

      ' EntitySetBase is a super type for 
      ' EntitySets and RelationshipSets. 
      ' Iterate through the collection to get each EntitySetBase.
      Dim baseSet As EntitySetBase
      For Each baseSet In container.BaseEntitySets
         ' Check if this instance is an EntitySet.
         If TypeOf baseSet Is EntitySet Then
           Console.WriteLine( _
              "  EntitySet Name: {0} , EntityType Name: {1} ", _
              baseSet.Name, baseSet.ElementType.FullName)
          End If

          ' RelationshipSet is a super type for AssociationSet.
          ' Check if this instance is an AssociationSet.
          If TypeOf baseSet Is AssociationSet Then
            Console.WriteLine( _
              "  AssociationSet Name: {0} , " + _
              "AssociationType Name: {1} ", _
              baseSet.Name, baseSet.ElementType.FullName)

            ' Get the AssociationSet.
            Dim associationSet As AssociationSet = _
               TryCast(baseSet, AssociationSet)

            ' Iterate through the collection to get 
            '  each AssociatedSetEnd.
            Dim endMember As AssociationSetEnd
            For Each endMember In associationSet.AssociationSetEnds
              Console.WriteLine( _
                 "   EntitySet Name: {0} , Name: {1} ", _
                 endMember.EntitySet, endMember.Name)
            Next
          End If
      Next
    Next
  End Sub
End Class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft