EntityContainer Classe

Definizione

Rappresenta un contenitore di entità in un modello concettuale. Un oggetto EntityContainer è un raggruppamento logico di set di entità e set di associazioni.

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
Ereditarietà
EntityContainer

Esempio

Nell'esempio di codice seguente viene illustrato come ottenere un'area di lavoro metadati dalla connessione e quindi utilizzarla per recuperare informazioni sui contenitori di entità nel modello di dati specificato. Si noti che l'area di lavoro metadati è un componente del servizio di runtime che fornisce supporto per il recupero dei metadati.

Nell'esempio di codice vengono utilizzati un oggetto CSpace e un oggetto SSpace per specificare il modello. CSpace rappresenta il nome predefinito per il modello concettuale. SSpace rappresenta il nome predefinito per il modello di archiviazione.

Il GetEntityContainers metodo ottiene una raccolta di contenitori di entità e quindi esegue l'iterazione tramite la raccolta per ottenere ogni set di entità e associazione impostato nel contenitore specificato. L'esempio di codice usa il modello 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  

Commenti

A livello concettuale la classe EntityContainer rappresenta un contenitore che verrà mappato a un oggetto di database nello schema dei metadati di archiviazione. A livello di archiviazione la classe EntityContainer rappresenta una descrizione delle relazioni tra tabelle e/o chiavi che rendono persistenti i dati per le applicazioni compilate in base al modello. Per altre informazioni sui contenitori di entità in un modello concettuale, vedere Contenitore di entità.

Proprietà

BaseEntitySets

Ottiene un elenco di set di entità e di set di associazioni inclusi in EntityContainer.

BuiltInTypeKind

Ottiene il tipo del tipo incorporato per EntityContainer.

Documentation

Ottiene o imposta la documentazione associata al tipo.

(Ereditato da MetadataItem)
FunctionImports

Specifica una raccolta di elementi EdmFunction. Ogni funzione contiene i dettagli di una stored procedure presente nel database o equivalente CommandText mappata a un'entità e alle relative proprietà.

MetadataProperties

Ottiene l'elenco di proprietà del tipo corrente.

(Ereditato da MetadataItem)
Name

Ottiene il nome di EntityContainer.

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetEntitySetByName(String, Boolean)

Restituisce un oggetto EntitySet utilizzando il nome specificato per il set di entità.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetRelationshipSetByName(String, Boolean)

Restituisce un oggetto RelationshipSet utilizzando il nome specificato per il set di relazioni.

GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce il nome di EntityContainer.

TryGetEntitySetByName(String, Boolean, EntitySet)

Restituisce un oggetto EntitySet utilizzando il nome specificato per il set di entità.

TryGetRelationshipSetByName(String, Boolean, RelationshipSet)

Restituisce un oggetto RelationshipSet utilizzando il nome specificato per il set di relazioni.

Si applica a