방법: 복합 형식으로 개체 쿼리 만들기 및 실행(Entity Framework)

이 예제에서는 방법: 복합 형식으로 모델 정의(Entity Framework) 항목에서 정의한 스키마를 사용합니다.

복합 형식을 사용하여 프로젝트를 만들려면

  1. CustomerComplexAddrClient 콘솔 응용 프로그램 프로젝트를 만들고 System.Data.EntitySystem.Runtime.Serialization에 대한 참조를 추가합니다.

  2. 방법: 복합 형식으로 모델 정의(Entity Framework) 항목에서 설명한 프로젝트에서 빌드한 dll에 대한 참조를 추가합니다.

  3. 방법: 복합 형식으로 모델 정의(Entity Framework) 항목의 스키마를 실행 파일과 같은 폴더에 추가합니다.

  4. 예제에서처럼 응용 프로그램 구성 파일을 만듭니다.

  5. 예제의 코드를 Program.cs 파일에 복사합니다.

  6. 다음과 같은 내용의 응용 프로그램 구성 파일을 추가합니다.

  7. 프로젝트를 빌드하고 실행합니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="CustomerComplexAddressContext" 
         connectionString="metadata=.;
         provider=System.Data.SqlClient;
         provider connection string=&quot;
         Data Source=serverName;
         Initial Catalog=CustomerWComplexAddr;
         Integrated Security=True;
         multipleactiveresultsets=true&quot;"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

예제

예제 코드에서는 CAddress 복합 형식의 CCustomers 및 내부 속성을 모두 표시합니다. 개체 컨텍스트에는 복합 속성 Address가 있는 CCustomers의 컬렉션이 포함됩니다. Address 속성의 형식은 CAddress입니다. 내부 속성은 모두 CCustomer 형식의 인스턴스에서 액세스할 수 있습니다.

Option Explicit On
Option Strict On
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports CustomerComplexAddress_VB
Imports CustomerComplexAddress_VB.CustomerComplexAddr

Module Module1
    Sub Main()
        Try
            Using objCtx As CustomerComplexAddrContext = _
                    New CustomerComplexAddrContext()
                For Each customer As CCustomer In objCtx.CCustomers
                    Console.WriteLine("Customer Id: " & _
                        "{0} {1}" & vbNewLine & "{2} {3}," & _
                        "{4} {5}" & vbNewLine & "Phone: {6}", _
                        customer.CustomerId.ToString(), _
                        customer.CompanyName, _
                        customer.Address.StreetAddress, _
                        customer.Address.City, _
                        customer.Address.Region, _
                        customer.Address.PostalCode, _
                        customer.Address.Phone)
                    Console.Write(vbNewLine)
                Next
            End Using
        Catch ex As Exception
            Console.WriteLine(ex.ToString())
        End Try
    End Sub
End Module
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CustomerComplexAddress;

namespace CustomerComplexAddressClient
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (CustomerComplexAddressContext objCtx =
                    new CustomerComplexAddressContext())
                {
                    foreach (CCustomer customer in objCtx.CCustomers)
                    {
                        Console.WriteLine("Customer Id: " +
                            "{0} {1}\r\n{2} {3}," +
                            "{4} {5}\n\rPhone: {6}", 
                            customer.CustomerId.ToString(),
                            customer.CompanyName,
                            customer.Address.StreetAddress,
                            customer.Address.City,
                            customer.Address.Region,
                            customer.Address.PostalCode,
                            customer.Address.Phone);
                    }

                    
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

참고 항목

작업

방법: 복합 형식으로 모델 정의(Entity Framework)
방법: 복합 형식으로 개체 추가 및 수정(Entity Framework)

개념

복합 형식(EDM)