在 Silverlight 的 ADO.Net Data Services 中批量加载属性
我在 Silverlight 3 中使用 ADO.Net Data Services (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);
但是,我不知道如何获取 DataServiceRequest 对象以将加载属性请求传递给 BeginExecuteBatch。是否可以通过获取 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()
});
I'm using ADO.Net Data Services (Astoria) in Silverlight 3 and I want to delay loading properties on an entity until after the initial load. However, when I'm ready to load them I'd like to batch the load requests together.
// 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've gotten this far:
// 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);
However, I can't figure how how to get a DataServiceRequest object for a load property request to pass to BeginExecuteBatch. Is it possible to issue these requests (and potentially others that aren't associated with the customer property load) in the same batch by getting a DataServiceQuery?
Something like this:
// 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()
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LoadProperty 方法不使用数据服务中可用的任何标准类型。然而,数据服务足够智能,可以计算出
。
与生成的 Uri 相同
因此,如果您想在批量查询中调用LoadProperty,您可以非常轻松地生成所需的Uri。见下文。
所以现在你可以这样做。
剩下的唯一一件事是,这只会返回给您对象,它不会做的是将返回值分配给实体属性,您必须在 BatchCallback 上自己执行此操作。
无论如何,彼得希望这对你有所帮助。
如果您有任何需要,请告诉我
问候
丹尼尔
The LoadProperty method does not use any standard types that are available to you in dataservice. However data service is intelligent enough to figure that
is the same as
The Uri generated is the same.
So if you want to Call LoadProperty in batch query you can generate the Uri required quite easily. See below.
So Now you can do this.
The only thing left is that this will only return to you the object(s) what it wont do is assign the return value(s) to the entity property, that will you have to do it yourself on your BatchCallback.
Anyhow Peter Hope this helps you on what you want.
If there is anything you need let me know
Regards
Daniel