DataServiceContext.LoadProperty Method (Object, String)

Loads deferred content for a specified property from the data service.

Not supported by the WCF Data Services 5.0 client for Silverlight.

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

Syntax

'Declaration
Public Function LoadProperty ( _
    entity As Object, _
    propertyName As String _
) As QueryOperationResponse
'Usage
Dim instance As DataServiceContext 
Dim entity As Object 
Dim propertyName As String 
Dim returnValue As QueryOperationResponse 

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

Parameters

  • entity
    Type: System.Object
    The entity that contains the property to load.
  • propertyName
    Type: System.String
    The name of the property of the specified entity to load.

Return Value

Type: System.Data.Services.Client.QueryOperationResponse
The response to the load operation.

Remarks

Calling this method invokes a network operation to fetch the property value. The property specified may be any one of the properties on the entity, including properties that represent associations or links.

If the property represents an association, link or deferred property, calling this method provides the client a way to lazily load related resources.

If the entity is in the unchanged or modified state, the property value loads the related entities and marks them unchanged with unchanged links

If the property is already loaded, calling this method lets you refresh the value of the property.

Examples

The following example shows how to explicitly load the Customers object that is related to each returned Orders instance. This example uses the DataServiceContext generated by the Add Service Reference tool based on the Northwind data service, which is created when you complete the WCF Data Services?quickstart.

' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)

Try
    ' Enumerate over the top 10 orders obtained from the context.
    For Each order As Order In context.Orders.Take(10)
        ' Explicitly load the customer for each order.
        context.LoadProperty(order, "Customer")

        ' Write out customer and order information.
        Console.WriteLine("Customer: {0} - Order ID: {1}", _
                order.Customer.CompanyName, order.OrderID)
    Next
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);

try
{
    // Enumerate over the top 10 orders obtained from the context.
    foreach (Order order in context.Orders.Take(10))
    {
        // Explicitly load the customer for each order.
        context.LoadProperty(order, "Customer");

        // Write out customer and order information.
        Console.WriteLine("Customer: {0} - Order ID: {1}", 
            order.Customer.CompanyName, order.OrderID);
    }
}
catch (DataServiceQueryException ex)
{
    throw new ApplicationException(
        "An error occurred during query execution.", ex);
}

See Also

Reference

DataServiceContext Class

LoadProperty Overload

System.Data.Services.Client Namespace