EntityContainer EntityContainer EntityContainer EntityContainer Class

Definizione

Rappresenta un contenitore di entità in un modello concettuale.Represents an entity container in a conceptual model. Un oggetto EntityContainer è un raggruppamento logico di set di entità e set di associazioni.An EntityContainer is a logical grouping of entity sets and association sets.

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à

Esempi

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.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. Si noti che l'area di lavoro metadati è un componente del servizio di runtime che fornisce supporto per il recupero dei metadati.Note that the metadata workspace is a runtime service component that provides support for retrieving metadata.

Nell'esempio di codice vengono utilizzati un oggetto CSpace e un oggetto SSpace per specificare il modello.The code sample uses a CSpace and a SSpace to specify the model. CSpace rappresenta il nome predefinito per il modello concettuale.The CSpace represents the default name for the conceptual model. SSpace rappresenta il nome predefinito per il modello di archiviazione.The SSpace represents the default name for the storage model.

Il GetEntityContainers metodo ottiene una raccolta di contenitori di entità, quindi scorre la raccolta per ottenere ogni set di entità e set di associazioni nel contenitore specificato.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. Nell'esempio di codice viene utilizzato il modello AdventureWorks fornito nell'argomento Adventure Works Model (EDM) .The code sample uses the AdventureWorks Model that is provided in the Adventure Works Model (EDM) topic. Per un esempio del file di configurazione dell'applicazione, vedere il modello a oggetti Adventure Works in Applications (EDM).For an example of the application config file, see Adventure Works Object Model in Applications (EDM).

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.On the conceptual level, the EntityContainer class represents a container that will be mapped to a database object in the storage metadata schema. 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.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. Per ulteriori informazioni sui contenitori di entità in un modello concettuale, vedere Entity Containers (EDM).For more information about the entity containers in a conceptual model, see Entity Containers (EDM).

Proprietà

BaseEntitySets BaseEntitySets BaseEntitySets BaseEntitySets

Ottiene un elenco di set di entità e set di associazioni inclusi in EntityContainer.Gets a list of entity sets and association sets that this EntityContainer includes.

BuiltInTypeKind BuiltInTypeKind BuiltInTypeKind BuiltInTypeKind

Ottiene il tipo del tipo incorporato per EntityContainer.Gets the built-in type kind for this EntityContainer.

Documentation Documentation Documentation Documentation

Ottiene o imposta la documentazione associata al tipo.Gets or sets the documentation associated with this type.

(Inherited from MetadataItem)
FunctionImports FunctionImports FunctionImports FunctionImports

Specifica una raccolta di elementi EdmFunction.Specifies a collection of EdmFunction elements. Ogni funzione contiene i dettagli di una stored procedure esistente nel database o di un oggetto CommandText equivalente mappato in un'entità e nelle proprietà relative.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.

MetadataProperties MetadataProperties MetadataProperties MetadataProperties

Ottiene l'elenco di proprietà del tipo corrente.Gets the list of properties of the current type.

(Inherited from MetadataItem)
Name Name Name Name

Ottiene il nome di EntityContainer.Gets the name of this EntityContainer.

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEntitySetByName(String, Boolean) GetEntitySetByName(String, Boolean) GetEntitySetByName(String, Boolean) GetEntitySetByName(String, Boolean)

Restituisce un oggetto EntitySet utilizzando il nome specificato per il set di entità.Returns an EntitySet object by using the specified name for the entity set.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetRelationshipSetByName(String, Boolean) GetRelationshipSetByName(String, Boolean) GetRelationshipSetByName(String, Boolean) GetRelationshipSetByName(String, Boolean)

Restituisce un oggetto RelationshipSet utilizzando il nome specificato per il set di relazioni.Returns a RelationshipSet object by using the specified name for the relationship set.

GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Restituisce il nome dell'oggetto EntityContainer.Returns the name of this EntityContainer.

TryGetEntitySetByName(String, Boolean, EntitySet) TryGetEntitySetByName(String, Boolean, EntitySet) TryGetEntitySetByName(String, Boolean, EntitySet) TryGetEntitySetByName(String, Boolean, EntitySet)

Restituisce un oggetto EntitySet utilizzando il nome specificato per il set di entità.Returns an EntitySet object by using the specified name for the entity set.

TryGetRelationshipSetByName(String, Boolean, RelationshipSet) TryGetRelationshipSetByName(String, Boolean, RelationshipSet) TryGetRelationshipSetByName(String, Boolean, RelationshipSet) TryGetRelationshipSetByName(String, Boolean, RelationshipSet)

Restituisce un oggetto RelationshipSet utilizzando il nome specificato per il set di relazioni.Returns a RelationshipSet object by using the specified name for the relationship set.

Si applica a