Condividi tramite


Metodo DataServiceContext.LoadProperty (Object, String, Uri)

Carica una pagina di entità correlate tramite l'URI del collegamento successivo fornito.

Non supportato dal client di WCF Data Services 5.0 per Silverlight.

Spazio dei nomi  System.Data.Services.Client
Assembly:  Microsoft.Data.Services.Client (in Microsoft.Data.Services.Client.dll)

Sintassi

'Dichiarazione
Public Function LoadProperty ( _
    entity As Object, _
    propertyName As String, _
    nextLinkUri As Uri _
) As QueryOperationResponse
'Utilizzo
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

Parametri

  • entity
    Tipo: System.Object
    Entità contenente la proprietà da caricare.
  • propertyName
    Tipo: System.String
    Nome della proprietà dell'entità specificata da caricare.
  • nextLinkUri
    Tipo: System.Uri
    URI utilizzato per caricare la pagina di risultati successiva.

Valore restituito

Tipo: System.Data.Services.Client.QueryOperationResponse
Istanza dell'oggetto QueryOperationResponse<T> contenente i risultati della richiesta.

Eccezioni

Eccezione Condizione
InvalidOperationException

Se entity è in uno stato Detached o Added.

Osservazioni

Se entity è in uno stato Unchanged o Modified, le entità correlate vengono caricate in uno stato Unchanged e anche i collegamenti tra le entità vengono creati in uno stato Unchanged.

Se entity è in uno stato Deleted, le entità correlate vengono caricate in uno stato Unchanged e anche i collegamenti tra le entità vengono creati in uno stato Deleted.

Esempi

In questo esempio vengono restituite entità Orders correlate con ogni entità Customers e viene utilizzato un loop do?while per caricare pagine di entità Customers e un loop while nidificato per caricare pagine di entità Orders correlate dal servizio dati. Il metodo LoadProperty viene utilizzato per caricare pagine di entità Orders correlate.

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

Vedere anche

Riferimento

DataServiceContext Classe

Overload LoadProperty

Spazio dei nomi System.Data.Services.Client

Altre risorse

Procedura: caricare risultati di paging (WCF Data Services)

Caricamento di contenuto posticipato (WCF Data Services)