DataServiceContext.LoadProperty Metodo

Definizione

Carica il contenuto posticipato dal servizio dati.

Overload

LoadProperty(Object, String)

Carica il contenuto posticipato per una proprietà specificata dal servizio dati.

LoadProperty(Object, String, DataServiceQueryContinuation)

Carica la pagina successiva di entità correlate dal servizio dati tramite l'oggetto di continuazione di query fornito.

LoadProperty(Object, String, Uri)

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

LoadProperty<T>(Object, String, DataServiceQueryContinuation<T>)

Carica la pagina successiva di entità correlate dal servizio dati tramite l'oggetto generico di continuazione di query fornito.

LoadProperty(Object, String)

Carica il contenuto posticipato per una proprietà specificata dal servizio dati.

public:
 System::Data::Services::Client::QueryOperationResponse ^ LoadProperty(System::Object ^ entity, System::String ^ propertyName);
public System.Data.Services.Client.QueryOperationResponse LoadProperty (object entity, string propertyName);
member this.LoadProperty : obj * string -> System.Data.Services.Client.QueryOperationResponse
Public Function LoadProperty (entity As Object, propertyName As String) As QueryOperationResponse

Parametri

entity
Object

Entità contenente la proprietà da caricare.

propertyName
String

Nome della proprietà dell'entità specificata da caricare.

Restituisce

Risposta all'operazione di caricamento.

Esempio

Nell'esempio seguente viene illustrato come caricare in modo esplicito l'oggetto Customers correlato a ogni istanza di Orders restituita. In questo esempio viene usato lo DataServiceContext strumento Aggiungi riferimento al servizio basato sul servizio dati Northwind, creato al termine dell'WCF Data Services .

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

Commenti

La chiamata di questo metodo richiama un'operazione di rete per recuperare il valore della proprietà. La proprietà specificata può essere una qualsiasi proprietà nell'entità, incluse le proprietà che rappresentano associazioni o collegamenti.

Se la proprietà rappresenta un'associazione o un collegamento oppure una proprietà posticipata, la chiamata di questo metodo fornisce al client un metodo per caricare in ritardo le risorse correlate.

Se l'entità è nello stato non modificato o modificato, il valore della proprietà carica le entità correlate contrassegnandole come non modificate con collegamenti non modificati.

Se la proprietà è già caricata, la chiamata di questo metodo consente di aggiornare il valore della proprietà.

Si applica a

LoadProperty(Object, String, DataServiceQueryContinuation)

Carica la pagina successiva di entità correlate dal servizio dati tramite l'oggetto di continuazione di query fornito.

public:
 System::Data::Services::Client::QueryOperationResponse ^ LoadProperty(System::Object ^ entity, System::String ^ propertyName, System::Data::Services::Client::DataServiceQueryContinuation ^ continuation);
public System.Data.Services.Client.QueryOperationResponse LoadProperty (object entity, string propertyName, System.Data.Services.Client.DataServiceQueryContinuation continuation);
member this.LoadProperty : obj * string * System.Data.Services.Client.DataServiceQueryContinuation -> System.Data.Services.Client.QueryOperationResponse
Public Function LoadProperty (entity As Object, propertyName As String, continuation As DataServiceQueryContinuation) As QueryOperationResponse

Parametri

entity
Object

Entità contenente la proprietà da caricare.

propertyName
String

Nome della proprietà dell'entità specificata da caricare.

continuation
DataServiceQueryContinuation

Oggetto DataServiceQueryContinuation<T> che rappresenta la pagina successiva di dati delle entità correlate da caricare dal servizio dati.

Restituisce

Risposta contenente la pagina successiva di dati delle entità correlate.

Eccezioni

Se entity è in uno stato Detached o Added.

Commenti

Se entity è in uno stato Unchanged o Modified, le entità correlate vengono caricate come oggetti in uno stato Unchanged, con i collegamenti sempre in uno stato Unchanged.

Se entity è in uno stato Deleted, le entità correlate vengono caricate come oggetti in uno stato Unchanged, con i collegamenti sempre in uno stato Deleted.

Si applica a

LoadProperty(Object, String, Uri)

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

public:
 System::Data::Services::Client::QueryOperationResponse ^ LoadProperty(System::Object ^ entity, System::String ^ propertyName, Uri ^ nextLinkUri);
public System.Data.Services.Client.QueryOperationResponse LoadProperty (object entity, string propertyName, Uri nextLinkUri);
member this.LoadProperty : obj * string * Uri -> System.Data.Services.Client.QueryOperationResponse
Public Function LoadProperty (entity As Object, propertyName As String, nextLinkUri As Uri) As QueryOperationResponse

Parametri

entity
Object

Entità contenente la proprietà da caricare.

propertyName
String

Nome della proprietà dell'entità specificata da caricare.

nextLinkUri
Uri

URI utilizzato per caricare la pagina di risultati successiva.

Restituisce

Istanza dell'oggetto QueryOperationResponse<T> contenente i risultati della richiesta.

Eccezioni

Se entity è in uno stato Detached o Added.

Esempio

In questo esempio vengono restituite entità Orders correlate con ogni entità Customers e vengono usati un ciclo do…while per caricare pagine di entità Customers e un ciclo while annidato 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.
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);
}
' 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

Commenti

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 i collegamenti tra le entità vengono creati in uno stato Deleted.

Vedi anche

Si applica a

LoadProperty<T>(Object, String, DataServiceQueryContinuation<T>)

Carica la pagina successiva di entità correlate dal servizio dati tramite l'oggetto generico di continuazione di query fornito.

public:
generic <typename T>
 System::Data::Services::Client::QueryOperationResponse<T> ^ LoadProperty(System::Object ^ entity, System::String ^ propertyName, System::Data::Services::Client::DataServiceQueryContinuation<T> ^ continuation);
public System.Data.Services.Client.QueryOperationResponse<T> LoadProperty<T> (object entity, string propertyName, System.Data.Services.Client.DataServiceQueryContinuation<T> continuation);
member this.LoadProperty : obj * string * System.Data.Services.Client.DataServiceQueryContinuation<'T> -> System.Data.Services.Client.QueryOperationResponse<'T>
Public Function LoadProperty(Of T) (entity As Object, propertyName As String, continuation As DataServiceQueryContinuation(Of T)) As QueryOperationResponse(Of T)

Parametri di tipo

T

Tipo di elemento della raccolta da caricare.

Parametri

entity
Object

Entità contenente la proprietà da caricare.

propertyName
String

Nome della proprietà dell'entità specificata da caricare.

continuation
DataServiceQueryContinuation<T>

Oggetto DataServiceQueryContinuation<T> che rappresenta la pagina successiva di dati delle entità correlate da caricare dal servizio dati.

Restituisce

Risposta contenente la pagina successiva di dati delle entità correlate.

Eccezioni

Se entity è in uno stato Detached o Added.

Commenti

Se entity è in uno stato Unchanged o Modified, le entità correlate vengono caricate come oggetti in uno stato Unchanged, con i collegamenti sempre in uno stato Unchanged.

Se entity è in uno stato Deleted, le entità correlate vengono caricate come oggetti in uno stato Unchanged, con i collegamenti sempre in uno stato Deleted.

Si applica a