Language

DataServiceContext.LoadProperty メソッド

定義

遅延コンテンツをデータ サービスから読み込みます。

オーバーロード

名前 説明
LoadProperty(Object, String)

指定したプロパティの遅延コンテンツをデータ サービスから読み込みます。

LoadProperty(Object, String, DataServiceQueryContinuation)

指定されたクエリ継続オブジェクトを使用して、データ サービスから関連エンティティの次のページを読み込みます。

LoadProperty(Object, String, Uri)

指定された次のリンク URI を使用して、関連エンティティのページを読み込みます。

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

指定されたジェネリック クエリ継続オブジェクトを使用して、データ サービスから関連エンティティの次のページを読み込みます。

LoadProperty(Object, String)

指定したプロパティの遅延コンテンツをデータ サービスから読み込みます。

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

パラメーター

entity
Object

読み込むプロパティを含むエンティティ。

propertyName
String

読み込む指定したエンティティのプロパティの名前。

返品

読み込み操作に対する応答。

例

次の例は、返された各Customers インスタンスに関連するOrders オブジェクトを明示的に読み込む方法を示しています。 この例では、Northwind データ サービスに基づいてサービス参照の追加ツールによって生成された DataServiceContext を使用します。これは、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

注釈

このメソッドを呼び出すと、ネットワーク操作が呼び出され、プロパティ値がフェッチされます。 指定するプロパティは、関連付けまたはリンクを表すプロパティを含め、エンティティのプロパティのいずれかになります。

プロパティが関連付け、リンク、または遅延プロパティを表す場合、このメソッドを呼び出すと、クライアントは関連するリソースを遅延読み込みできます。

エンティティが変更されていない状態または変更された状態の場合、プロパティ値は関連エンティティを読み込み、変更されていないリンクでマークします

プロパティが既に読み込まれている場合は、このメソッドを呼び出すと、プロパティの値を更新できます。

適用対象

LoadProperty(Object, String, DataServiceQueryContinuation)

指定されたクエリ継続オブジェクトを使用して、データ サービスから関連エンティティの次のページを読み込みます。

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

パラメーター

entity
Object

読み込むプロパティを含むエンティティ。

propertyName
String

読み込む指定したエンティティのプロパティの名前。

continuation
DataServiceQueryContinuation

データ サービスから読み込む関連エンティティの次のページを表す DataServiceQueryContinuation<T> オブジェクト。

返品

関連エンティティ データの次のページを含む応答。

例外

entityがDetachedまたはAdded状態にある場合。

注釈

entityがUnchanged状態またはModified状態の場合、関連エンティティはUnchanged状態のオブジェクトとして読み込まれ、リンクもUnchanged状態になります。

entityがDeleted状態の場合、関連エンティティはUnchanged状態のオブジェクトとして読み込まれ、リンクはDeleted状態になります。

適用対象

LoadProperty(Object, String, Uri)

指定された次のリンク URI を使用して、関連エンティティのページを読み込みます。

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

パラメーター

entity
Object

読み込むプロパティを含むエンティティ。

propertyName
String

読み込む指定したエンティティのプロパティの名前。

nextLinkUri
Uri

次の結果ページの読み込みに使用される URI。

返品

要求の結果を含む QueryOperationResponse<T> のインスタンス。

例外

entityがDetachedまたはAdded状態にある場合。

例

この例では、各Orders エンティティに関連するCustomers エンティティを返し、do…while ループを使用してエンティティ ページCustomers読み込み、入れ子になったwhile ループを使用して、関連するOrdersエンティティのページをデータ サービスから読み込みます。 LoadProperty メソッドは、関連する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

注釈

entityがUnchangedまたはModified状態の場合、関連エンティティはUnchanged状態で読み込まれ、エンティティ間のリンクもUnchanged状態で作成されます。

entityがDeleted状態の場合、関連エンティティはUnchanged状態で読み込まれ、エンティティ間のリンクはDeleted状態で作成されます。

こちらもご覧ください

適用対象

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

指定されたジェネリック クエリ継続オブジェクトを使用して、データ サービスから関連エンティティの次のページを読み込みます。

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)

型パラメーター

T

読み込むコレクションの要素型。

パラメーター

entity
Object

読み込むプロパティを含むエンティティ。

propertyName
String

読み込む指定したエンティティのプロパティの名前。

continuation
DataServiceQueryContinuation<T>

データ サービスから読み込む関連エンティティの次のページを表す DataServiceQueryContinuation<T> オブジェクト。

返品

関連エンティティ データの次のページを含む応答。

例外

entityがDetachedまたはAdded状態にある場合。

注釈

entityがUnchanged状態またはModified状態の場合、関連エンティティはUnchanged状態のオブジェクトとして読み込まれ、リンクもUnchanged状態になります。

entityがDeleted状態の場合、関連エンティティはUnchanged状態のオブジェクトとして読み込まれ、リンクはDeleted状態になります。

適用対象