System.Data.Metadata.Edm 네임스페이스

System.Data.Metadata.Edm 네임스페이스에는 Entity Framework에서 사용하는 모델에 적용되는 개념을 나타내는 형식 집합과 응용 프로그램에서 메타데이터 작업을 수행하는 데 도움을 주는 클래스 집합이 포함됩니다.

==> GlobalItem 클래스 : 모든 EDM(EDM(Entity Data Model)) 형식과 엔터티 컨테이너의 기본 항목 클래스를 나타낸다.

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

class BrowseTypes
{
  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();

         // Browse the metadata type hierarchy in the conceptual model.
         BrowseTypesExample(workspace, DataSpace.CSpace);

         // Browse the metadata type hierarchy in the storage model.
         BrowseTypesExample(workspace, DataSpace.SSpace);
      }
    }
    catch (MetadataException exceptionMetadata)
    {
      Console.WriteLine("MetadataException: {0}",
                      exceptionMetadata.Message);
    }
    catch (System.Data.MappingException exceptionMapping)
    {
      Console.WriteLine("MappingException: {0}",
                       exceptionMapping.Message);
    }
  }

  private static void BrowseTypesExample(MetadataWorkspace workspace,
    DataSpace model)
  {
    // Get a collection of the GlobalItems.
    // An GlobalItem class is the base class for
    // the entity data model types and entity containers.
    ReadOnlyCollection<GlobalItem> items =
         workspace.GetItems<GlobalItem>(model);

    // Iterate through the collection to get each item.
    foreach (GlobalItem item in items)
    {
       EntityContainer entityContainer = item as EntityContainer;
       if (entityContainer != null)
       {
         Console.WriteLine(
            "EntityContainer Name: {0}",
             entityContainer.Name);
                continue;
       }

       EntityType entityType = item as EntityType;
       if (entityType != null)
       {
          Console.WriteLine(
            "EntityType Name: {0}, Namespace: {1}",
             entityType.Name, entityType.NamespaceName);
          continue;
       }

       AssociationType associationType = item as AssociationType;
       if (associationType != null)
       {
          Console.WriteLine(
            "AssociationType Name: {0}, Namespace: {1}",
            associationType.Name, associationType.NamespaceName);
          continue;
        }

        PrimitiveType primType = item as PrimitiveType;
        if (primType != null)
        {
          Console.WriteLine(
            "PrimitiveType Name: {0}, Namespace: {1}",
            primType.Name, primType.NamespaceName);
            continue;
        }

        EdmFunction function = item as EdmFunction;
        if (function != null)
        {
          Console.WriteLine(
            "Function Name: {0}, Namespace: {1}",
            function.Name, function.NamespaceName);
          continue;
        }
      }
  }
}




참고 : http://msdn.microsoft.com/ko-kr/library/system.data.metadata.edm.globalitem.aspx


Posted by 사나에