等待 DomainContext.Load从带有连接的实体查询完成(通过“选择新”返回新类型)
我的应用程序整合了其他数据库的数据以用于报告目的。我们无法链接数据库,因此所有数据处理都必须在代码中完成 - 这很好,因为我们希望在导入期间允许手动验证。
某些用户将能够通过 Silverlight 4 前端开始更新。
我在数据库 x 中有 3 个表,它们由一个 EF4 模型 (ModelX) 提供。我想将这些表连接在一起,选择特定列并将结果作为存在于不同 EF4 模型 (ModelY) 中的新实体返回。我正在使用这个查询:
var myQuery = from i in DBx.table1 from it in DBx.table2 from h in DBx.table3 where (i.id==it.id && h.otherid == i.otherid) select new ModelYServer {Name = i.name,Thing = it.thing, Stuff = h.stuff};
我所坚持的一点是如何执行该查询,并等待异步调用完成。通常,我会使用:
DomainContext.Load<T>(myQuery).Completed += (sender,args) =>
{List<T> myList = ((LoadOperation<T>)sender.Entities.ToList();};
但我无法将 myQuery (IEnumerable)传递到 DomainContext.Load() 中,因为它需要 EntityQuery。数据集非常大,并且需要长达 30 秒的时间才能返回,因此我肯定需要等待才能继续。
那么谁能告诉我如何等待 IEnumerable 查询完成,或者建议一种更好的方法来执行此操作(很可能有一种)。
谢谢米克
My app consolidates data from other DBs for reporting purposes. We can't link the databases, so all the data processing has to be done in code - this is fine as we want to allow manual validation during the imports.
Certain users will be able to start an update through the Silverlight 4 front end.
I have 3 tables in database x that are fed from one EF4 Model (ModelX). I want to join those tables together, select specific columns and return the result as a new entity that exists in a different EF4 Model (ModelY). I'm using this query:
var myQuery = from i in DBx.table1 from it in DBx.table2 from h in DBx.table3 where (i.id==it.id && h.otherid == i.otherid) select new ModelYServer {Name = i.name,Thing = it.thing, Stuff = h.stuff};
The bit i'm stuck on, is how to execute that query, and wait until the Asynchronous call has completed. Normally, i'd use:
DomainContext.Load<T>(myQuery).Completed += (sender,args) =>
{List<T> myList = ((LoadOperation<T>)sender.Entities.ToList();};
but I can't pass myQuery (an IEnumerable) into the DomainContext.Load() as that expects an EntityQuery. The dataset is very large, and is taking up to 30 seconds to return, so I definitely need to wait before continuing.
So can anyone tell me how I can wait for the IEnumerable query to complete, or suggest a better way of doing this (there very likely is one).
Thanks
Mick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种简单的方法是通过调用
ToList
来强制它进行评估:(我已将您的
where
子句更改为早期表上的联接,因为这就是您有效执行的操作在我看来,这更惯用。)One simple way is just to force it to evaluate by calling
ToList
:(I've changed your
where
clause into joins on the earlier tables, as that's what you were effectively doing and this is more idiomatic, IMO.)