다음을 통해 공유


형식(메타데이터)

형식은 EDM(엔터티 데이터 모델)의 기본이 되는 최상위 구조입니다. ADO.NET에서는 System.Data.Metadata.Edm 네임스페이스를 제공하며, 여기에는 엔터티 프레임워크에서 EDM으로 정의된 개념을 나타내는 형식의 집합이 포함되어 있습니다. 엔터티 프레임워크에서 사용되는 모델에 대한 자세한 내용은 Entity Framework의 데이터 모델링메타데이터 작업 영역 개요를 참조하십시오.

메타데이터 형식 계층 구조 개요의 설명처럼 EdmType은 EDM의 형식을 나타내는 클래스의 기본 클래스입니다. SimpleType, StructuralType, CollectionTypeRefType과 같은 최상위 형식은 EdmType에서 파생됩니다.

  • SimpleType은 기본 형식을 정의합니다. 단순 형식에 대한 자세한 내용은 단순 형식(메타데이터)을 참조하십시오.

  • StructuralType은 멤버가 있는 메타데이터 형식 계층 구조의 모든 형식에 대한 기본 형식입니다. 구조 형식에 대한 자세한 내용은 구조 형식(메타데이터)을 참조하십시오.

  • CollectionType은 특정 형식의 인스턴스 컬렉션을 정의합니다.

  • RefType에는 엔터티를 사용하는 작업의 엔터티 주소가 저장됩니다.

엔터티 데이터 모델 형식 항목에서는 EDM에서 형식을 사용하는 방법에 대한 자세한 정보도 제공합니다.

다음 코드 샘플에서는 연결에서 메타데이터 작업 영역을 가져온 다음 이 메타데이터 작업 영역을 사용하여 지정된 모델의 특정 형식 및 기타 모든 형식에 대한 정보를 검색하는 방법을 보여 줍니다. 코드 샘플에서는 CSpaceSSpace를 사용하여 모델을 지정합니다. CSpace는 개념적 모델의 기본 이름을 나타내고 SSpace는 저장소 모델의 기본 이름을 나타냅니다. 메타데이터 작업 영역은 메타데이터 검색을 지원하는 런타임 서비스 구성 요소입니다.

코드 샘플에서는 AdventureWorks 전체 모델(EDM) 항목에서 제공하는 Adventureworks 모델을 사용합니다. 응용 프로그램 구성 파일의 예를 보려면 AdventureWorks 개체 모델 사용(EDM)을 참조하십시오.

// The first example:
using System;
using System.Data;
using System.Data.EntityClient;
using System.Collections.ObjectModel;
using System.Data.Metadata.Edm;

class GetTypeExample
{
  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 an EntityType object by using the specified type name, 
        // the namespace name, and the model. 
        EdmType departmentType1 = workspace.GetType(
              "Department", "AdventureWorksModel", DataSpace.CSpace);

        Console.WriteLine(
           "Type found in the conceptual model Name: {0}, {1} ",
           departmentType1.Name, 
           departmentType1.NamespaceName);

        // Get an EntityType object by using the specified type name, 
        // the namespace name, and the model. 
        EdmType departmentType2 = workspace.GetType( 
           "Department", "AdventureWorksModel.Store",
           DataSpace.SSpace);

        Console.WriteLine(
          "Type found in the storage model Name: {0}, {1} ",
          departmentType2.Name,
          departmentType2.NamespaceName);
      }
    }
    catch (MetadataException exceptionMetadata)
    {
      Console.WriteLine("MetadataException: {0}", 
                       exceptionMetadata.Message);
    }
    catch (System.Data.MappingException exceptionMapping)
    {
      Console.WriteLine("MappingException: {0}",
                       exceptionMapping.Message);
    }
  }
}
// The second example:
using System;
using System.Data;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Collections.ObjectModel;

class GetTypesExample
{
  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 types from the conceptual model.
          GetTypesFromModel(workspace, DataSpace.CSpace);

          // Get types from the storage model.
          GetTypesFromModel(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 GetTypesFromModel(
    MetadataWorkspace workspace, DataSpace model)
  {
    // Get a collection of the EdmTypes. 
    // An EdmType class is the base class for the classes 
    // that represent types in the Entity Data Model (EDM).
    ReadOnlyCollection<EdmType> types =
          workspace.GetItems<EdmType>(model);

    // Iterate through the collection to get each edm type, 
    // specifically each entity type.
    foreach (EdmType item in types)
    {
       EntityType entityType = item as EntityType;
       if (entityType != null)
       {
          Console.WriteLine("Type: {0}, Type in Model: {1} ",
                item.GetType().FullName, item.FullName);
       }
     }
  }
}
' The first example:
Imports System
Imports System.Data
Imports System.Data.EntityClient
Imports System.Data.Metadata.Edm

Class GetTypeExample
   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 conection.
          connection.Open()

          ' Access the metadata workspace.
           Dim workspace As MetadataWorkspace = _
             connection.GetMetadataWorkspace

           ' Get an EntityType object by using the specified type name, 
           ' the namespace name, and the model. 
           Dim departmentType1 As EdmType = _
              workspace.GetType("Department", "AdventureWorksModel", _
              DataSpace.CSpace)
           Console.WriteLine( _
           "Type found in the conceptual model Name: {0}, {1} ", _
           departmentType1.Name, _
           departmentType1.NamespaceName)

           ' Get an EntityType object by using the specified type name, 
           ' the namespace name, and the model. 
           Dim departmentType2 As EdmType = _
               workspace.GetType("Department", _
               "AdventureWorksModel.Store", _
               DataSpace.SSpace)
           Console.WriteLine( _
              "Type found in the storage model Name: {0}, {1} ", _
              departmentType2.Name, _
              departmentType2.NamespaceName)
        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
End Class
' The second example:
Imports System
Imports System.Collections.ObjectModel
Imports System.Data
Imports System.Data.EntityClient
Imports System.Data.Metadata.Edm

Class GetTypesExample
   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 conection.
         connection.Open()

         ' Access the metadata workspace.
         Dim workspace As MetadataWorkspace = _
           connection.GetMetadataWorkspace

         ' Get types from the conceptual model.
         GetTypesFromModel(workspace, DataSpace.CSpace)

         ' Get types from the storage model.
         GetTypesFromModel(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 GetTypesFromModel( _
     ByVal workspace As MetadataWorkspace, ByVal model As DataSpace)
     ' Get a collection of the EdmTypes. 
     ' An EdmType class is the base class for the classes 
     ' that represent types in the Entity Data Model (EDM).
     Dim types As ReadOnlyCollection(Of EdmType) = _
         workspace.GetItems(Of EdmType)(model)
     Dim item As EdmType

     ' Iterate through the collection to get each edm type, 
     ' specifically each entity type.
     For Each item In types
       Dim entityType As EntityType = TryCast(item, EntityType)
       If (Not entityType Is Nothing) Then
         Console.WriteLine("Type: {0}, Type in Model: {1} ", _
             item.GetType.FullName, item.FullName)
        End If
     Next
   End Sub
End Class

단원 내용

참고 항목

개념

메타데이터 형식 계층 구조
메타데이터 형식 계층 구조 개요
엔터티 데이터 모델 형식