DataServiceContext.LoadProperty Método

Definición

Carga contenido diferido del servicio de datos.

Sobrecargas

Nombre Description
LoadProperty(Object, String)

Carga contenido diferido para una propiedad especificada del servicio de datos.

LoadProperty(Object, String, DataServiceQueryContinuation)

Carga la página siguiente de entidades relacionadas desde el servicio de datos mediante el objeto de continuación de consulta proporcionado.

LoadProperty(Object, String, Uri)

Carga una página de entidades relacionadas mediante el URI de vínculo siguiente proporcionado.

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

Carga la página siguiente de entidades relacionadas desde el servicio de datos mediante el objeto de continuación de consulta genérico proporcionado.

LoadProperty(Object, String)

Carga contenido diferido para una propiedad especificada del servicio de datos.

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

Parámetros

entity
Object

Entidad que contiene la propiedad que se va a cargar.

propertyName
String

Nombre de la propiedad de la entidad especificada que se va a cargar.

Devoluciones

Respuesta a la operación de carga.

Ejemplos

En el ejemplo siguiente se muestra cómo cargar explícitamente el Customers objeto relacionado con cada instancia devuelta Orders . En este ejemplo se usa el DataServiceContext generado por la herramienta Agregar referencia de servicio basada en el servicio de datos Northwind, que se crea cuando se completa 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

Comentarios

Al llamar a este método, se invoca una operación de red para capturar el valor de la propiedad. La propiedad especificada puede ser cualquiera de las propiedades de la entidad, incluidas las propiedades que representan asociaciones o vínculos.

Si la propiedad representa una asociación, vínculo o propiedad diferida, llamar a este método proporciona al cliente una manera de cargar recursos relacionados de forma diferida.

Si la entidad está en estado sin cambios o modificados, el valor de la propiedad carga las entidades relacionadas y las marca sin cambios con vínculos sin cambios.

Si la propiedad ya está cargada, llamar a este método le permite actualizar el valor de la propiedad.

Se aplica a

LoadProperty(Object, String, DataServiceQueryContinuation)

Carga la página siguiente de entidades relacionadas desde el servicio de datos mediante el objeto de continuación de consulta proporcionado.

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

Parámetros

entity
Object

Entidad que contiene la propiedad que se va a cargar.

propertyName
String

Nombre de la propiedad de la entidad especificada que se va a cargar.

continuation
DataServiceQueryContinuation

Objeto DataServiceQueryContinuation<T> que representa la página siguiente de entidades relacionadas que se van a cargar desde el servicio de datos.

Devoluciones

Respuesta que contiene la página siguiente de datos de entidad relacionados.

Excepciones

Cuando entity está en el Detached estado o Added .

Comentarios

Cuando entity está en un Unchanged estado o Modified , las entidades relacionadas se cargan como objetos en un Unchanged estado, con vínculos también en Unchanged estado.

Cuando entity está en un Deleted estado, las entidades relacionadas se cargan como objetos en un Unchanged estado, con vínculos que están en estado Deleted .

Se aplica a

LoadProperty(Object, String, Uri)

Carga una página de entidades relacionadas mediante el URI de vínculo siguiente proporcionado.

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

Parámetros

entity
Object

Entidad que contiene la propiedad que se va a cargar.

propertyName
String

Nombre de la propiedad de la entidad especificada que se va a cargar.

nextLinkUri
Uri

URI que se usa para cargar la página de resultados siguiente.

Devoluciones

Instancia de QueryOperationResponse<T> que contiene los resultados de la solicitud.

Excepciones

Cuando entity está en un Detached estado o Added .

Ejemplos

En este ejemplo se devuelven entidades relacionadas Orders con cada Customers entidad y se usa un do…while bucle para cargar Customers páginas de entidades y un bucle anidado while para cargar páginas de entidades relacionadas Orders desde el servicio de datos. El LoadProperty método se usa para cargar páginas de entidades relacionadas Orders .

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

Comentarios

Cuando entity está en un Unchanged estado o Modified , las entidades relacionadas se cargan en el Unchanged estado y los vínculos entre las entidades también se crean en un Unchanged estado.

Cuando entity está en un Deleted estado, las entidades relacionadas se cargan en el Unchanged estado y los vínculos entre las entidades se crean en el Deleted estado .

Consulte también

Se aplica a

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

Carga la página siguiente de entidades relacionadas desde el servicio de datos mediante el objeto de continuación de consulta genérico proporcionado.

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)

Parámetros de tipo

T

Tipo de elemento de colección que se va a cargar.

Parámetros

entity
Object

Entidad que contiene la propiedad que se va a cargar.

propertyName
String

Nombre de la propiedad de la entidad especificada que se va a cargar.

continuation
DataServiceQueryContinuation<T>

Objeto DataServiceQueryContinuation<T> que representa la página siguiente de entidades relacionadas que se van a cargar desde el servicio de datos.

Devoluciones

Respuesta que contiene la página siguiente de datos de entidad relacionados.

Excepciones

Cuando entity está en el Detached estado o Added .

Comentarios

Cuando entity está en un Unchanged estado o Modified , las entidades relacionadas se cargan como objetos en un Unchanged estado, con vínculos también en Unchanged estado.

Cuando entity está en un Deleted estado, las entidades relacionadas se cargan como objetos en un Unchanged estado, con vínculos que están en estado Deleted .

Se aplica a