EntityCollection<TEntity>.Load(MergeOption) 메서드

정의

지정된 병합 옵션을 사용하여 관련 개체를 컬렉션에 로드합니다.

public:
 override void Load(System::Data::Objects::MergeOption mergeOption);
public override void Load (System.Data.Objects.MergeOption mergeOption);
override this.Load : System.Data.Objects.MergeOption -> unit
Public Overrides Sub Load (mergeOption As MergeOption)

매개 변수

mergeOption
MergeOption

같은 ObjectContext에 대한 이전 쿼리에서 반환된 개체가 있는 경우 이 컬렉션의 개체와 병합할 방법을 지정합니다.

예제

이 예제는 Adventure Works Sales 모델을 기반으로 합니다. 이 예제에서 코드를 실행하려면 이미 AdventureWorks 판매 모델을 프로젝트에 추가하고 Entity Framework를 사용하도록 프로젝트를 구성해야 합니다. 이렇게 하려면 방법: 수동으로 Entity Framework 프로젝트 구성방법: 수동으로 모델 및 매핑 파일 정의의 절차를 완료합니다.

다음은 엔터티에 대한 관련 SalesOrderHeader 개체를 로드하는 Contact 예제입니다.

// Specify the customer ID.
int contactID = 4332;

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    context.ContextOptions.LazyLoadingEnabled = false;

    // Get a specified customer by contact ID.
    var contact =
        (from c in context.Contacts
         where c.ContactID == contactID
         select c).First();

    // Load the orders for the customer explicitly.
    if (!contact.SalesOrderHeaders.IsLoaded)
    {
        contact.SalesOrderHeaders.Load();
    }

    foreach (SalesOrderHeader order in contact.SalesOrderHeaders)
    {
        // Load the items for the order if not already loaded.
        if (!order.SalesOrderDetails.IsLoaded)
        {
            order.SalesOrderDetails.Load();
        }

        Console.WriteLine(String.Format("PO Number: {0}",
            order.PurchaseOrderNumber));
        Console.WriteLine(String.Format("Order Date: {0}",
            order.OrderDate.ToString()));
        Console.WriteLine("Order items:");
        foreach (SalesOrderDetail item in order.SalesOrderDetails)
        {
            Console.WriteLine(String.Format("Product: {0} "
                + "Quantity: {1}", item.ProductID.ToString(),
                item.OrderQty.ToString()));
        }
    }
}

설명

이 메서드는 컬렉션을 로드하기 전에 내부 RelatedEnd.ValidateLoad 메서드를 호출하여 에 대한 호출 Load 에 올바른 조건이 있는지 확인합니다. 메서드는 RelatedEnd.ValidateLoad 다음을 확인합니다.

컬렉션의 개체가 이미 에 ObjectContext로드된 경우 메서드는 Load 매개 변수로 지정된 mergeOption 를 적용합니다MergeOption. 자세한 내용은 Id 확인, 상태 관리 및 변경 내용 추적합니다.

관련 개체를 명시적으로 로드하려면 탐색 속성에서 Load 반환된 관련 끝에서 메서드를 호출해야 합니다. 일 대 다 관계의 경우 에서 메서드를 Load 호출합니다 EntityCollection<TEntity>. 일대일 관계의 경우 에서 을 호출합니다 LoadEntityReference<TEntity>. 그러면 관련 개체 데이터가 개체 컨텍스트로 로드됩니다. 루프(For Each...NextVisual Basic의 경우)를 사용하여 foreach 반환된 결과의 컬렉션을 열거하고 결과에서 각 엔터티에 대한 및 EntityCollection<TEntity> 속성에 대해 메서드를 EntityReference<TEntity> 조건부로 호출 Load 할 수 있습니다.

메서드는 Load 데이터 원본에서 관련 개체를 로드합니다 IsLoadedtrue.

참고

(C#) 또는 For Each (Visual Basic) 열거 중에 메서드를 foreach 호출 Load 하면 Object Services에서 새 데이터 판독기를 열려고 시도합니다. 연결 문자열 를 지정하여 여러 활성 결과 집합을 multipleactiveresultsets=true 사용하도록 설정하지 않으면 이 작업이 실패합니다. 쿼리 결과를 컬렉션에 로드할 List<T> 수도 있습니다. 이렇게 하면 데이터 판독기가 닫히며 참조된 개체를 로드하기 위해 컬렉션을 열거할 수 있습니다.

EntityCollection<TEntity>.Load 메서드는 메서드와 EntityReference<TEntity>.Load 동기화됩니다.

적용 대상