Share via


DataServiceContext.LoadProperty Metode

Definisi

Memuat konten yang ditangguhkan dari layanan data.

Overload

LoadProperty(Object, String)

Memuat konten yang ditangguhkan untuk properti tertentu dari layanan data.

LoadProperty(Object, String, DataServiceQueryContinuation)

Memuat halaman berikutnya dari entitas terkait dari layanan data dengan menggunakan objek kelanjutan kueri yang disediakan.

LoadProperty(Object, String, Uri)

Memuat halaman entitas terkait dengan menggunakan URI tautan berikutnya yang disediakan.

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

Memuat halaman berikutnya dari entitas terkait dari layanan data dengan menggunakan objek kelanjutan kueri generik yang disediakan.

LoadProperty(Object, String)

Memuat konten yang ditangguhkan untuk properti tertentu dari layanan data.

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

Parameter

entity
Object

Entitas yang berisi properti yang akan dimuat.

propertyName
String

Nama properti entitas yang ditentukan untuk dimuat.

Mengembalikan

Respons terhadap operasi pemuatan.

Contoh

Contoh berikut menunjukkan cara memuat Customers objek yang terkait secara eksplisit dengan setiap instans yang dikembalikan Orders . Contoh ini menggunakan DataServiceContext yang dihasilkan oleh alat Tambahkan Referensi Layanan berdasarkan layanan data Northwind, yang dibuat saat Anda menyelesaikan Layanan Data 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

Keterangan

Memanggil metode ini memanggil operasi jaringan untuk mengambil nilai properti. Properti yang ditentukan mungkin salah satu properti pada entitas, termasuk properti yang mewakili asosiasi atau tautan.

Jika properti mewakili asosiasi, tautan, atau properti yang ditangguhkan, memanggil metode ini memberi klien cara untuk memuat sumber daya terkait dengan malas.

Jika entitas berada dalam status tidak berubah atau dimodifikasi, nilai properti memuat entitas terkait dan menandainya tidak berubah dengan tautan yang tidak berubah

Jika properti sudah dimuat, memanggil metode ini memungkinkan Anda menyegarkan nilai properti.

Berlaku untuk

LoadProperty(Object, String, DataServiceQueryContinuation)

Memuat halaman berikutnya dari entitas terkait dari layanan data dengan menggunakan objek kelanjutan kueri yang disediakan.

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

Parameter

entity
Object

Entitas yang berisi properti yang akan dimuat.

propertyName
String

Nama properti entitas yang ditentukan untuk dimuat.

continuation
DataServiceQueryContinuation

Objek DataServiceQueryContinuation<T> yang mewakili halaman berikutnya dari entitas terkait untuk dimuat dari layanan data.

Mengembalikan

Respons yang berisi halaman berikutnya dari data entitas terkait.

Pengecualian

Ketika entity berada dalam status Detached atau Added .

Keterangan

Saat entity berada dalam status Unchanged atau Modified , entitas terkait dimuat sebagai objek dalam status Unchanged , dengan tautan juga dalam Unchanged status .

Saat entity berada dalam status Deleted , entitas terkait dimuat sebagai objek dalam status Unchanged , dengan tautan yang berada dalam Deleted status .

Berlaku untuk

LoadProperty(Object, String, Uri)

Memuat halaman entitas terkait dengan menggunakan URI tautan berikutnya yang disediakan.

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

Parameter

entity
Object

Entitas yang berisi properti yang akan dimuat.

propertyName
String

Nama properti entitas yang ditentukan untuk dimuat.

nextLinkUri
Uri

URI yang digunakan untuk memuat halaman hasil berikutnya.

Mengembalikan

Instans QueryOperationResponse<T> yang berisi hasil permintaan.

Pengecualian

Saat entity berada dalam status Detached atau Added .

Contoh

Contoh ini mengembalikan entitas terkait Orders dengan setiap Customers entitas dan menggunakan perulangan do…while untuk memuat Customers halaman entitas dan perulangan berlapis while untuk memuat halaman entitas terkait Orders dari layanan data. Metode LoadProperty ini digunakan untuk memuat halaman entitas terkait 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

Keterangan

Ketika entity berada dalam status Unchanged atau Modified , entitas terkait dimuat dalam Unchanged status , dan tautan antara entitas juga dibuat dalam status Unchanged .

Ketika entity berada dalam status Deleted , entitas terkait dimuat dalam Unchanged status , dan tautan antara entitas dibuat dalam Deleted status .

Lihat juga

Berlaku untuk

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

Memuat halaman berikutnya dari entitas terkait dari layanan data dengan menggunakan objek kelanjutan kueri generik yang disediakan.

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)

Jenis parameter

T

Jenis elemen koleksi yang akan dimuat.

Parameter

entity
Object

Entitas yang berisi properti yang akan dimuat.

propertyName
String

Nama properti entitas yang ditentukan untuk dimuat.

continuation
DataServiceQueryContinuation<T>

Objek DataServiceQueryContinuation<T> yang mewakili halaman berikutnya dari entitas terkait untuk dimuat dari layanan data.

Mengembalikan

Respons yang berisi halaman berikutnya dari data entitas terkait.

Pengecualian

Ketika entity berada dalam status Detached atau Added .

Keterangan

Saat entity berada dalam status Unchanged atau Modified , entitas terkait dimuat sebagai objek dalam status Unchanged , dengan tautan juga dalam Unchanged status .

Saat entity berada dalam status Deleted , entitas terkait dimuat sebagai objek dalam status Unchanged , dengan tautan yang berada dalam Deleted status .

Berlaku untuk