DataServiceContext.LoadProperty Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Carrega conteúdo adiado do serviço de dados.
Sobrecargas
| Nome | Description |
|---|---|
| LoadProperty(Object, String) |
Carrega conteúdo adiado para uma propriedade especificada do serviço de dados. |
| LoadProperty(Object, String, DataServiceQueryContinuation) |
Carrega a próxima página de entidades relacionadas do serviço de dados usando o objeto de continuação de consulta fornecido. |
| LoadProperty(Object, String, Uri) |
Carrega uma página de entidades relacionadas usando o próximo URI de link fornecido. |
| LoadProperty<T>(Object, String, DataServiceQueryContinuation<T>) |
Carrega a próxima página de entidades relacionadas do serviço de dados usando o objeto de continuação de consulta genérico fornecido. |
LoadProperty(Object, String)
Carrega conteúdo adiado para uma propriedade especificada do serviço de dados.
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
A entidade que contém a propriedade a ser carregada.
- propertyName
- String
O nome da propriedade da entidade especificada a ser carregada.
Retornos
A resposta à operação de carga.
Exemplos
O exemplo a seguir mostra como carregar explicitamente o Customers objeto relacionado a cada instância retornada Orders . Este exemplo usa o DataServiceContext gerado pela ferramenta Adicionar Referência de Serviço com base no serviço de dados Northwind, que é criado quando você conclui os Serviços de Dados do WCF.
// 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
Comentários
Chamar esse método invoca uma operação de rede para buscar o valor da propriedade. A propriedade especificada pode ser qualquer uma das propriedades na entidade, incluindo propriedades que representam associações ou links.
Se a propriedade representar uma associação, um link ou uma propriedade adiada, chamar esse método fornecerá ao cliente uma maneira de carregar de forma preguiçosa os recursos relacionados.
Se a entidade estiver no estado inalterado ou modificado, o valor da propriedade carregará as entidades relacionadas e as marcará inalteradas com links inalterados
Se a propriedade já estiver carregada, chamar esse método permitirá que você atualize o valor da propriedade.
Aplica-se a
LoadProperty(Object, String, DataServiceQueryContinuation)
Carrega a próxima página de entidades relacionadas do serviço de dados usando o objeto de continuação de consulta fornecido.
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
A entidade que contém a propriedade a ser carregada.
- propertyName
- String
O nome da propriedade da entidade especificada a ser carregada.
- continuation
- DataServiceQueryContinuation
Um DataServiceQueryContinuation<T> objeto que representa a próxima página de entidades relacionadas a serem carregadas do serviço de dados.
Retornos
A resposta que contém a próxima página de dados de entidade relacionados.
Exceções
Comentários
Quando entity estiver em um Unchanged estado ou Modified estado, as entidades relacionadas serão carregadas como objetos em um Unchanged estado, com links também no Unchanged estado.
Quando entity está em um Deleted estado, as entidades relacionadas são carregadas como objetos em um Unchanged estado, com links que estão no Deleted estado.
Aplica-se a
LoadProperty(Object, String, Uri)
Carrega uma página de entidades relacionadas usando o próximo URI de link fornecido.
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
A entidade que contém a propriedade a ser carregada.
- propertyName
- String
O nome da propriedade da entidade especificada a ser carregada.
- nextLinkUri
- Uri
O URI usado para carregar a próxima página de resultados.
Retornos
Uma instância que QueryOperationResponse<T> contém os resultados da solicitação.
Exceções
Exemplos
Este exemplo retorna entidades relacionadas Orders com cada Customers entidade e usa um do…while loop para carregar Customers páginas de entidades e um loop aninhado while para carregar páginas de entidades relacionadas Orders do serviço de dados. O LoadProperty método é usado para carregar 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
Comentários
Quando entity está em um Unchanged estado ou Modified estado, as entidades relacionadas são carregadas no Unchanged estado e os links entre as entidades também são criados em um Unchanged estado.
Quando entity está em um Deleted estado, as entidades relacionadas são carregadas no Unchanged estado e os links entre as entidades são criados no Deleted estado.
Confira também
Aplica-se a
LoadProperty<T>(Object, String, DataServiceQueryContinuation<T>)
Carrega a próxima página de entidades relacionadas do serviço de dados usando o objeto de continuação de consulta genérico fornecido.
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 da coleção a ser carregada.
Parâmetros
- entity
- Object
A entidade que contém a propriedade a ser carregada.
- propertyName
- String
O nome da propriedade da entidade especificada a ser carregada.
- continuation
- DataServiceQueryContinuation<T>
Um DataServiceQueryContinuation<T> objeto que representa a próxima página de entidades relacionadas a serem carregadas do serviço de dados.
Retornos
A resposta que contém a próxima página de dados de entidade relacionados.
Exceções
Comentários
Quando entity estiver em um Unchanged estado ou Modified estado, as entidades relacionadas serão carregadas como objetos em um Unchanged estado, com links também no Unchanged estado.
Quando entity está em um Deleted estado, as entidades relacionadas são carregadas como objetos em um Unchanged estado, com links que estão no Deleted estado.