DataServiceContext.LoadProperty 方法 (Object, String)
從資料服務載入指定之屬性的延遲內容。
不受到適用於 Silverlight 的 WCF Data Services 5.0 用戶端支援。
命名空間: System.Data.Services.Client
組件: Microsoft.Data.Services.Client (在 Microsoft.Data.Services.Client.dll 中)
語法
'宣告
Public Function LoadProperty ( _
entity As Object, _
propertyName As String _
) As QueryOperationResponse
'用途
Dim instance As DataServiceContext
Dim entity As Object
Dim propertyName As String
Dim returnValue As QueryOperationResponse
returnValue = instance.LoadProperty(entity, _
propertyName)
public QueryOperationResponse LoadProperty(
Object entity,
string propertyName
)
public:
QueryOperationResponse^ LoadProperty(
Object^ entity,
String^ propertyName
)
member LoadProperty :
entity:Object *
propertyName:string -> QueryOperationResponse
public function LoadProperty(
entity : Object,
propertyName : String
) : QueryOperationResponse
參數
- entity
型別:System.Object
包含要載入之屬性的實體。
- propertyName
型別:System.String
要載入的指定之實體的屬性名稱。
傳回值
型別:System.Data.Services.Client.QueryOperationResponse
載入作業的回應。
備註
呼叫這個方法會叫用擷取屬性值的網路作業。 指定的屬性可能是實體上的任何一個屬性,包括代表關聯或連結的屬性。
如果屬性表示關聯或連結或是擱置的屬性,呼叫這個方法則會提供用戶端一個延遲載入資源的方式。
如果實體處於未變更或已修改狀態,屬性值會載入相關實體,並將這些具有未變更連結的實體標記成未變更。
如果已載入該屬性,則呼叫此方法會讓您重新整理屬性的值。
範例
下列範例示範如何明確地載入與所傳回之每個 Orders 執行個體相關的 Customers 物件。 此範例使用「加入服務參考」工具所產生的 DataServiceContext,並根據完成 WCF Data Services 快速入門時所建立的 Northwind 資料服務。
' 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
// 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);
}