【发布时间】:2009-12-15 01:13:14
【问题描述】:
我在 Silverlight 3 中使用 ADO.Net 数据服务 (Astoria),我想将实体上的属性加载延迟到初始加载之后。但是,当我准备好加载它们时,我想将加载请求一起批处理。
// this is what I want to avoid
var c = (from c in ctx.Customers.Expand("Address,Phone,Email")
where c.Id = 12
select c).Take(1) as DataServiceQuery<Customer>;
我已经走到这一步了:
// I can do this instead
var c = (from c in ctx.Customers // .Expand("Address,Phone,Email")
where c.Id = 12
select c).Take(1) as DataServiceQuery<Customer>;
c.BeginExecute(CustomerCallback, objState);
...
// Later, when I want properties, I need to do this
ctx.BeginLoadProperty(c, "Address", AddressCallback, objState);
ctx.BeginLoadProperty(c, "Phone", PhoneCallback, objState);
ctx.BeginLoadProperty(c, "Email", EmailCallback, objState);
但是,我不知道如何获取要传递给 BeginExecuteBatch 的加载属性请求的 DataServiceRequest 对象。是否可以通过获取 DataServiceQuery 在同一批次中发出这些请求(以及可能与客户属性负载无关的其他请求)?
类似这样的:
// c is the customer from the above load
ctx.BeginExecuteBatch(BatchCallback, objState, new []{
ctx.GetLoadQuery(c, "Address"),
ctx.GetLoadQuery(c, "Phone"),
ctx.GetLoadQuery(c, "Email"),
GetOtherNonPropertyQuery()
});
【问题讨论】:
标签: entity-framework silverlight-3.0 wcf-data-services