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 对象。 此示例使用基于 Northwind 数据服务(在您完成 WCF 数据服务?快速入门时创建)的“添加服务引用”工具所生成的 DataServiceContext。
' 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);
}