EntityContainer Clase

Definición

Representa un contenedor de entidades en un modelo conceptual. es EntityContainer una agrupación lógica de conjuntos de entidades y conjuntos de asociación.

public ref class EntityContainer sealed : System::Data::Metadata::Edm::GlobalItem
public sealed class EntityContainer : System.Data.Metadata.Edm.GlobalItem
type EntityContainer = class
    inherit GlobalItem
Public NotInheritable Class EntityContainer
Inherits GlobalItem
Herencia
EntityContainer

Ejemplos

En el ejemplo de código siguiente se muestra cómo obtener un área de trabajo de metadatos de la conexión y, a continuación, usar esa área de trabajo de metadatos para recuperar información sobre los contenedores de entidades en el modelo de datos especificado. Tenga en cuenta que el área de trabajo de metadatos es un componente de servicio en tiempo de ejecución que proporciona compatibilidad para recuperar metadatos.

El ejemplo de código usa y CSpace un SSpace para especificar el modelo. CSpace representa el nombre predeterminado del modelo conceptual. SSpace representa el nombre predeterminado del modelo de almacenamiento.

El GetEntityContainers método obtiene una colección de contenedores de entidades y, a continuación, recorre en iteración la colección para obtener cada conjunto de entidades y conjunto de asociaciones en el contenedor especificado. El ejemplo de código usa el modelo AdventureWorks.

using System;  
using System.Data;  
using System.Data.EntityClient;  
using System.Data.Metadata.Edm;  
using System.Collections.ObjectModel;  

class GetEntityContainerExample  
{  
  static void Main()  
  {  
    try  
    {  
       // Establish a connection to the underlying data provider by   
       // using the connection string specified in the config file.  
       using (EntityConnection connection =  
          new EntityConnection("Name=AdventureWorksEntities"))  
       {  
         // Open the connection.  
         connection.Open();  

         // Access the metadata workspace.  
         MetadataWorkspace workspace =   
            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);  
       }  
    }  
    catch (MetadataException exceptionMetadata)  
    {  
      Console.WriteLine("MetadataException: {0}",   
                       exceptionMetadata.Message);  
    }  
    catch (System.Data.MappingException exceptionMapping)  
    {  
      Console.WriteLine("MappingException: {0}",  
                       exceptionMapping.Message);  
    }  
  }  

  public static void GetEntityContainers(  
      MetadataWorkspace workspace, DataSpace model)  
  {  
    // Get a collection of the entity containers.  
    ReadOnlyCollection<EntityContainer> containers =   
         workspace.GetItems<EntityContainer>(model);  

    // Iterate through the collection to get each entity container.  
    foreach (EntityContainer 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.  
       foreach (EntitySetBase baseSet in container.BaseEntitySets)  
       {  
          // Check if this instance is an EntitySet.  
          if (baseSet is EntitySet)  
          {  
             Console.WriteLine(  
                "  EntitySet Name: {0} , EntityType Name: {1} ",  
                baseSet.Name, baseSet.ElementType.FullName);  
          }  

         // RelationshipSet is a super type for AssociationSet.  
         // Check if this instance is an AssociationSet.  
         if (baseSet is AssociationSet)  
         {  
            Console.WriteLine(  
               "  AssociationSet Name: {0} , " +  
               "AssociationType Name: {1} ",  
                baseSet.Name, baseSet.ElementType.FullName);  

            // Get the AssociationSet.  
            AssociationSet associationSet =   
                  baseSet as AssociationSet;  

            // Iterate through the collection to get   
            // each AssociatedSetEnd.  
            foreach (AssociationSetEnd end in   
               associationSet.AssociationSetEnds)  
            {  
               Console.WriteLine(  
                  "   EntitySet Name: {0} , Name: {1} ",  
                  end.EntitySet, end.Name);  
            }  
         }  
      }  
    }  
  }  
}  
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 connection.  
        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  

Comentarios

En el nivel conceptual, la EntityContainer clase representa un contenedor que se asignará a un objeto de base de datos en el esquema de metadatos de almacenamiento. En el nivel de almacenamiento, la EntityContainer clase representa una descripción de las relaciones de tabla o clave que conservan los datos de las aplicaciones basadas en el modelo. Para obtener más información sobre los contenedores de entidades en un modelo conceptual, consulte Contenedor de entidades.

Propiedades

Nombre Description
BaseEntitySets

Obtiene una lista de conjuntos de entidades y conjuntos de asociaciones que incluye.EntityContainer

BuiltInTypeKind

Obtiene el tipo de tipo integrado para este EntityContainerobjeto .

Documentation

Obtiene o establece la documentación asociada a este tipo.

(Heredado de MetadataItem)
FunctionImports

Especifica una colección de EdmFunction elementos. Cada función contiene los detalles de un procedimiento almacenado que existe en la base de datos o equivalente CommandText que se asigna a una entidad y sus propiedades.

MetadataProperties

Obtiene la lista de propiedades del tipo actual.

(Heredado de MetadataItem)
Name

Obtiene el nombre de este EntityContainerobjeto .

Métodos

Nombre Description
Equals(Object)

Determina si el objeto especificado es igual al objeto actual.

(Heredado de Object)
GetEntitySetByName(String, Boolean)

Devuelve un EntitySet objeto mediante el nombre especificado para el conjunto de entidades.

GetHashCode()

Actúa como la función hash predeterminada.

(Heredado de Object)
GetRelationshipSetByName(String, Boolean)

Devuelve un RelationshipSet objeto utilizando el nombre especificado para el conjunto de relaciones.

GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Objectactual.

(Heredado de Object)
ToString()

Devuelve el nombre de este EntityContainerobjeto .

TryGetEntitySetByName(String, Boolean, EntitySet)

Devuelve un EntitySet objeto mediante el nombre especificado para el conjunto de entidades.

TryGetRelationshipSetByName(String, Boolean, RelationshipSet)

Devuelve un RelationshipSet objeto utilizando el nombre especificado para el conjunto de relaciones.

Se aplica a