The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataServiceContext.LoadProperty Method (Object, String, Uri)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Loads a page of related entities by using the supplied next link URI.

Namespace:   System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public QueryOperationResponse LoadProperty(
	object entity,
	string propertyName,
	Uri nextLinkUri


Type: System.Object

The entity that contains the property to load.

Type: System.String

The name of the property of the specified entity to load.

Type: System.Uri

The URI that is used to load the next results page.

Return Value

Type: System.Data.Services.Client.QueryOperationResponse

An instance of QueryOperationResponse<T> that contains the results of the request.

Exception Condition

When entity is in a Detached or Added state.

When entity is in an Unchanged or Modified state, the related entities are loaded in the Unchanged state, and the links between the entities are also created in an Unchanged state.

When entity is in a Deleted state, the related entities are loaded in the Unchanged state, and the links between the entities are created in the Deleted state.

This example returns related Orders entities with each Customers entity and uses a do…while loop to load Customers entities pages and a nested while loop to load pages of related Orders entities from the data service. The LoadProperty method is used to load pages of related Orders entities.

// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
DataServiceQueryContinuation<Customer> nextLink = null;
int pageCount = 0;
int innerPageCount = 0;

    // 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.
        // 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 = 

            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);

.NET Framework
Available since 3.5
Return to top