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 Project 방법: 모델 및 매핑 파일 수동으로 정의 절차를 완료합니다.

이 예제에서는 엔터티에 대한 관련 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 매개 변수로 지정된 개체를 MergeOptionmergeOption 적용합니다. 자세한 내용은 ID 확인, 상태 관리 및 변경 내용 추적을 참조하세요.

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

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

메모

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

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

적용 대상