ObjectQuery<T>.Include(String) 메서드

정의

쿼리 결과에 포함할 관련 개체를 지정합니다.

public:
 System::Data::Objects::ObjectQuery<T> ^ Include(System::String ^ path);
public System.Data.Objects.ObjectQuery<T> Include (string path);
member this.Include : string -> System.Data.Objects.ObjectQuery<'T>
Public Function Include (path As String) As ObjectQuery(Of T)

매개 변수

path
String

쿼리 결과에 반환할 관련 개체의 목록입니다(점으로 구분됨).

반환

쿼리 경로가 정의된 새 ObjectQuery<T>입니다.

예외

path이(가) null인 경우

path이(가) empty인 경우

예제

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    // Define an object query with a path that returns
    // orders and items for a specific contact.
    Contact contact =
        context.Contacts.Include("SalesOrderHeaders.SalesOrderDetails")
        .FirstOrDefault();

    // Execute the query and display information for each item
    // in the orders that belong to the first contact.
    foreach (SalesOrderHeader order in contact
        .SalesOrderHeaders)
    {
        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()));
        }
    }
}

설명

쿼리 경로는 Entity SQL 및 LINQ 쿼리와 함께 사용할 수 있습니다.

경로는 모두 포함됩니다. 예를 들어 include 호출이 를 나타내는 Include("Orders.OrderLines")경우 는 포함될 뿐만 아니라 도 Orders포함됩니다OrderLines. 자세한 내용은 관련 개체 로드를 참조하세요.

메서드를 Include 호출할 때 쿼리 경로는 의 반환된 instance만 유효합니다ObjectQuery<T>. 및 개체 컨텍스트 자체의 ObjectQuery<T> 다른 인스턴스는 영향을 받지 않습니다.

메서드는 Include 쿼리 개체를 반환하므로 다음 예제와 같이 에서 이 메서드를 ObjectQuery<T> 여러 번 호출하여 쿼리에 대한 여러 경로를 지정할 수 있습니다.

// Create a SalesOrderHeader query with two query paths,
// one that returns order items and a second that returns the
// billing and shipping addresses for each order.
ObjectQuery<SalesOrderHeader> query =
    context.SalesOrderHeaders.Include("SalesOrderDetails").Include("Address");

적용 대상

추가 정보