EntityContainer Klasse

Definition

Stellt einen Entitätscontainer in einem konzeptionellen Modell dar. An EntityContainer ist eine logische Gruppierung von Entitätssätzen und Zuordnungssätzen.

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
Vererbung
EntityContainer

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie einen Metadatenarbeitsbereich aus der Verbindung abrufen und dann diesen Metadatenarbeitsbereich verwenden, um Informationen zu den Entitätscontainern im angegebenen Datenmodell abzurufen. Beachten Sie, dass der Metadatenarbeitsbereich eine Laufzeitdienstkomponente ist, die Unterstützung für das Abrufen von Metadaten bietet.

Im Codebeispiel wird ein CSpace und ein SSpace Code zum Angeben des Modells verwendet. Dies CSpace stellt den Standardnamen für das konzeptionelle Modell dar. Dies SSpace stellt den Standardnamen für das Speichermodell dar.

Die GetEntityContainers Methode ruft eine Auflistung von Entitätscontainern ab und durchläuft dann die Auflistung, um die einzelnen Entitätssätze und Zuordnungssätze im angegebenen Container abzurufen. Im Codebeispiel wird das AdventureWorks-Modell verwendet.

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  

Hinweise

Auf der konzeptionellen Ebene stellt die EntityContainer Klasse einen Container dar, der einem Datenbankobjekt im Speichermetadatenschema zugeordnet wird. Auf speicherebene stellt die EntityContainer Klasse eine Beschreibung der Tabellen- und/oder Schlüsselbeziehungen dar, die Daten für Anwendungen beibehalten, die auf dem Modell basieren. Weitere Informationen zu den Entitätscontainern in einem konzeptionellen Modell finden Sie unter Entity container.

Eigenschaften

Name Beschreibung
BaseEntitySets

Ruft eine Liste von Entitätssätzen und Zuordnungssätzen ab, die dies EntityContainer umfasst.

BuiltInTypeKind

Ruft die integrierte Typart für diese EntityContainerab.

Documentation

Dient zum Abrufen oder Festlegen der Dokumentation, die diesem Typ zugeordnet ist.

(Geerbt von MetadataItem)
FunctionImports

Gibt eine Auflistung von EdmFunction Elementen an. Jede Funktion enthält die Details einer gespeicherten Prozedur, die in der Datenbank oder einer Entsprechung CommandText vorhanden ist, die einer Entität und ihren Eigenschaften zugeordnet ist.

MetadataProperties

Ruft die Liste der Eigenschaften des aktuellen Typs ab.

(Geerbt von MetadataItem)
Name

Ruft den Namen dieses EntityContainer.

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
GetEntitySetByName(String, Boolean)

Gibt ein EntitySet Objekt mithilfe des angegebenen Namens für den Entitätssatz zurück.

GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetRelationshipSetByName(String, Boolean)

Gibt ein RelationshipSet Objekt mithilfe des angegebenen Namens für den Beziehungssatz zurück.

GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Gibt den Namen dieses Werts EntityContainerzurück.

TryGetEntitySetByName(String, Boolean, EntitySet)

Gibt ein EntitySet Objekt mithilfe des angegebenen Namens für den Entitätssatz zurück.

TryGetRelationshipSetByName(String, Boolean, RelationshipSet)

Gibt ein RelationshipSet Objekt mithilfe des angegebenen Namens für den Beziehungssatz zurück.

Gilt für: