Silverlight 子数据在查询中检索但在 OnLoadCompleted 方法中不可用
我有 Silverlight 4 RIA 服务应用程序,其中有一个 Sprinkler 类,它有一个子集合 Depths。 Sprinkler 和 Depth 是 SQL 数据库中的两个表,其中一个 Sprinkler 有多个深度。
我从一个类中调用查询,因此:
Context.GetRunsForSelectedSprinkler(currentSprinkler.CurrentSprinkler, OnLoadListCompleted, null);
我在同一类中访问查询结果的方法是:
private void OnLoadListCompleted(InvokeOperation<IEnumerable<Sprinkler>> invOp)
{
IEnumerable<Sprinkler> testRuns = invOp.Value;
}
我在 DomainService 中的查询是
[Invoke]
public IEnumerable<Sprinkler> GetRunsForSelectedSprinkler(string selectedSprinkler)
{
// this.ObjectContext.ContextOptions.LazyLoadingEnabled = true;
var sprinklers = (this.ObjectContext.Sprinklers.Include("Depths").Where(c => c.Sprinkler1 == selectedSprinkler));
return sprinklers;
}
我使用调试发现的是,在此查询 GetRunsForSelectedSprinkler 中,填充了洒水器中每个洒水器的深度集合适当地。但是,在接收此查询结果的 OnLoadListCompleted 方法中,虽然 Sprinkler 表中的洒水器数据存在,但由查询填充的 Depths 子集合(因为 Include("Depths"))现在不存在并且深度为空。不知何故,这个深度收藏在返回过程中丢失了。
有谁知道我该如何解决这个问题?
我广泛谷歌,我认为查询是正确的,但我找不到任何有关未能返回子集合的信息。
我尝试将 Depths 集合的 [Include] 放入元数据中,但这没有效果。我还尝试设置 this.ObjectContext.ContextOptions.LazyLoadingEnabled = true;
不是,但没有效果。 查询已正确执行,但结果未正确返回到 OnLoadListCompleted,并且以某种方式丢失了相关的子数据。
I have Silverlight 4 RIA service app with a class Sprinkler which has a child collection Depths. Sprinkler and Depth are two tables in an SQL database where one Sprinkler has many Depths.
I call the query from a class, thus:
Context.GetRunsForSelectedSprinkler(currentSprinkler.CurrentSprinkler, OnLoadListCompleted, null);
and the method where I access results of query in same class is:
private void OnLoadListCompleted(InvokeOperation<IEnumerable<Sprinkler>> invOp)
{
IEnumerable<Sprinkler> testRuns = invOp.Value;
}
My query in DomainService is
[Invoke]
public IEnumerable<Sprinkler> GetRunsForSelectedSprinkler(string selectedSprinkler)
{
// this.ObjectContext.ContextOptions.LazyLoadingEnabled = true;
var sprinklers = (this.ObjectContext.Sprinklers.Include("Depths").Where(c => c.Sprinkler1 == selectedSprinkler));
return sprinklers;
}
What I find using debug is that inside this query GetRunsForSelectedSprinkler the Depths collection for each sprinkler in sprinklers is populated properly. However, in the method OnLoadListCompleted which receives the result of this query, that although the sprinkler data from the Sprinkler table is there, the Depths child collection that was populated by the query (because of Include("Depths")) is now not there and Depths is null. Somehow this Depths collection has got lost during the return process.
Does anyone know how I can fix this?
I have Google extensively and I think the query is right, but I can't find anything about failure to return the child collection.
I have tried putting [Include] for the Depths collection in the metadata but that has no effect. I have also tried setting this.ObjectContext.ContextOptions.LazyLoadingEnabled = true;
and not, but it has no effect.
The query is executed correctly but the result is not returned correctly to OnLoadListCompleted and it is somehow losing the related child data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果人们不断猜测正确的关键词,最终人们可以谷歌找到正确的答案,我现在可以回答我自己的问题。我遵循了此页面上的建议:
http: //silverlightguy.com/2010/07/23/trick-for-solving-wcf-ria-services-issue/
解决了我的问题,并且子集合已正确返回。
这似乎是 RIA 服务中的一个已知问题,尽管很难发现。我还找到了这个页面:
InvokeOperation 实体变为 null
并尝试使我的查询而不是调用了但是还没解决完,发现上面的方法有效,所以不知道这样是否有效。
我也发现这个页面提到了这个问题,但没有跟进。
Silverlight 4 LoadOperation 返回 null
感谢上面发帖的人们。
If one keeps guessing at the right keywords eventually one can Google the right answer, and I can now answer my own question. I followed advice on this page:
http://silverlightguy.com/2010/07/23/trick-for-solving-wcf-ria-services-issue/
which solved my problem and the child collection was returned properly.
It seems that this is a known issue in RIA services, even if it is hard to discover. And I also found this page:
InvokeOperation entities become null
and tried to make mine a query instead of Invoke but hadn't finished solving it this way before finding the above method worked, so don't know if this works.
I also found this page mentioning the problem, but haven't followed up on it.
Silverlight 4 LoadOperation returns null
Thanks to those people who posted above.