다음을 통해 공유


DataServiceContext.LoadProperty 메서드 (Object, String, Uri)

제공된 다음 링크 URI를 사용하여 관련 엔터티 페이지를 로드합니다.

Silverlight용 WCF Data Services 5.0 클라이언트에서 지원되지 않습니다.

네임스페이스:  System.Data.Services.Client
어셈블리:  Microsoft.Data.Services.Client(Microsoft.Data.Services.Client.dll)

구문

‘선언
Public Function LoadProperty ( _
    entity As Object, _
    propertyName As String, _
    nextLinkUri As Uri _
) As QueryOperationResponse
‘사용 방법
Dim instance As DataServiceContext
Dim entity As Object
Dim propertyName As String
Dim nextLinkUri As Uri
Dim returnValue As QueryOperationResponse

returnValue = instance.LoadProperty(entity, _
    propertyName, nextLinkUri)
public QueryOperationResponse LoadProperty(
    Object entity,
    string propertyName,
    Uri nextLinkUri
)
public:
QueryOperationResponse^ LoadProperty(
    Object^ entity, 
    String^ propertyName, 
    Uri^ nextLinkUri
)
member LoadProperty : 
        entity:Object * 
        propertyName:string * 
        nextLinkUri:Uri -> QueryOperationResponse 
public function LoadProperty(
    entity : Object, 
    propertyName : String, 
    nextLinkUri : Uri
) : QueryOperationResponse

매개 변수

  • entity
    유형: System.Object
    로드할 속성을 포함하는 엔터티입니다.
  • propertyName
    유형: System.String
    로드할 지정된 엔터티의 속성 이름입니다.
  • nextLinkUri
    유형: System.Uri
    다음 결과 페이지를 로드하는 데 사용되는 URI입니다.

반환 값

유형: System.Data.Services.Client.QueryOperationResponse
요청의 결과를 포함하는 QueryOperationResponse<T> 인스턴스입니다.

예외

예외 조건
InvalidOperationException

entity가 Detached 또는 Added 상태인 경우

주의

entity가 Unchanged 또는 Modified 상태이면 관련 엔터티가 Unchanged 상태로 로드되고 엔터티 간의 관계도 Unchanged 상태로 만들어집니다.

entity가 Deleted 상태이면 관련 엔터티가 Unchanged 상태로 로드되고 엔터티 간의 링크가 Deleted 상태로 만들어집니다.

이 예제에서는 각 Customers 엔터티와 관련된 Orders 엔터티를 반환하고, do?while 루프를 사용하여 Customers 엔터티 페이지를 로드하고, 중첩된 while 루프를 사용하여 데이터 서비스에서 관련된 Orders 엔터티 페이지를 로드합니다. LoadProperty 메서드는 관련된 Orders 엔터티 페이지를 로드하는 데 사용됩니다.

' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
Dim nextLink As DataServiceQueryContinuation(Of Customer) = Nothing
Dim pageCount = 0
Dim innerPageCount = 0

Try
    ' Execute the query for all customers and related orders,
    ' and get the response object.
    Dim response = _
    CType(context.Customers.AddQueryOption("$expand", "Orders") _
            .Execute(), QueryOperationResponse(Of Customer))

    ' With a paged response from the service, use a do...while loop 
    ' to enumerate the results before getting the next link.
    Do
        ' Write the page number.
        Console.WriteLine("Customers Page {0}:", ++pageCount)

        ' If nextLink is not null, then there is a new page to load.
        If nextLink IsNot Nothing Then
            ' Load the new page from the next link URI.
            response = CType(context.Execute(Of Customer)(nextLink),  _
                    QueryOperationResponse(Of Customer))
        End If

        ' Enumerate the customers in the response.
        For Each c As Customer In response
            Console.WriteLine(vbTab & "Customer Name: {0}", c.CompanyName)
            Console.WriteLine(vbTab & "Orders Page {0}:", innerPageCount + 1)

            ' Get the next link for the collection of related Orders.
            Dim nextOrdersLink As DataServiceQueryContinuation(Of Order) = _
            response.GetContinuation(c.Orders)

            While nextOrdersLink IsNot Nothing
                For Each o As Order In c.Orders
                    ' Print out the orders.
                    Console.WriteLine(vbTab & vbTab & "OrderID: {0} - Freight: ${1}", _
                            o.OrderID, o.Freight)
                Next
                ' Load the next page of Orders.
                Dim ordersResponse = _
                context.LoadProperty(c, "Orders", nextOrdersLink)
                nextOrdersLink = ordersResponse.GetContinuation()
            End While
        Next
        ' Get the next link, and continue while there is a next link.
        nextLink = response.GetContinuation()
    Loop While nextLink IsNot Nothing
Catch ex As DataServiceQueryException
    Throw New ApplicationException( _
            "An error occurred during query execution.", ex)
End Try
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
DataServiceQueryContinuation<Customer> nextLink = null;
int pageCount = 0;
int innerPageCount = 0;

try
{
    // Execute the query for all customers and related orders,
    // and get the response object.
    var response =
        context.Customers.AddQueryOption("$expand", "Orders")
        .Execute() as QueryOperationResponse<Customer>;

    // With a paged response from the service, use a do...while loop 
    // to enumerate the results before getting the next link.
    do
    {
        // Write the page number.
        Console.WriteLine("Customers Page {0}:", ++pageCount);

        // If nextLink is not null, then there is a new page to load.
        if (nextLink != null)
        {
            // Load the new page from the next link URI.
            response = context.Execute<Customer>(nextLink)
                as QueryOperationResponse<Customer>;
        }

        // Enumerate the customers in the response.
        foreach (Customer c in response)
        {
            Console.WriteLine("\tCustomer Name: {0}", c.CompanyName);
            Console.WriteLine("\tOrders Page {0}:", ++innerPageCount);
            // Get the next link for the collection of related Orders.
            DataServiceQueryContinuation<Order> nextOrdersLink = 
                response.GetContinuation(c.Orders);

            while (nextOrdersLink != null)
            {
                foreach (Order o in c.Orders)
                {
                    // Print out the orders.
                    Console.WriteLine("\t\tOrderID: {0} - Freight: ${1}",
                        o.OrderID, o.Freight);
                }

                // Load the next page of Orders.
                var ordersResponse = context.LoadProperty(c, "Orders", nextOrdersLink);
                nextOrdersLink = ordersResponse.GetContinuation();
            }
        }
    }

    // Get the next link, and continue while there is a next link.
    while ((nextLink = response.GetContinuation()) != null);
}
catch (DataServiceQueryException ex)
{
    throw new ApplicationException(
        "An error occurred during query execution.", ex);
}

참고 항목

참조

DataServiceContext 클래스

LoadProperty 오버로드

System.Data.Services.Client 네임스페이스

관련 자료

방법: 페이징 결과 로드(WCF Data Services)

지연된 콘텐츠 로드(WCF Data Services)