具有 RIA 服务的 Silverlight 3 - 空白结果集/加载完成

发布于 2024-08-22 20:05:50 字数 1421 浏览 3 评论 0原文

大约上周我一直在拼命地试图找出我的脱节是什么,以至于我无法全神贯注于 RIA 服务。我仔细遵循Microsoft 教程视频 但我仍然遇到问题。也许我正在尝试做一些你做不到的事情,但很可能我只是以错误的方式去做。

在本教程中,他们使用的代码非常类似于:

IVCContext ctx = new IVCContext();
MyDataGrid.ItemsSource = ctx.ChairOptions;
ctx.Load(ctx.GetChairOptionsQuery());

使用在 ChairOptions 表中找到的信息填充 DataGrid。

但我想做的是直接访问结果,而不必将它们绑定到 DataGrid 或任何其他与此相关的控件。我想简单地获取结果集,然后按照我的意愿对其进行操作。

更具体地说,我想查看模型中附加到它的属性(名称、成本等)和关系(组、子组),以便我可以执行特殊操作并更改控件的内容。但似乎无论我尝试什么,我都会得到一个空白的结果集。

我尝试过类似的操作:

LocalContext ctx = new LocalContext();
var ResultSet = ctx.ChairOptions;
ctx.Load(ctx.GetChairOptionsQuery());

但 ResultSet 始终为空。

我觉得我无法弄清楚这一点的部分原因是因为我似乎无法准确找出第 #2 行的作业中发生了什么,以及 Load() 函数在第 #3 行实际上在做什么。在第一个示例中,它只是自动工作,但我真的很想了解发生了什么。

预先感谢您的任何帮助或参考。


编辑:

今天早上我醒来时突然意识到问题可能是什么。虽然代码看起来非常简单和程序化,但 Load 调用实际上是异步的,对吧?

如果这是正确的,那么问题就变成了,我如何知道它何时完成,以便我可以对结果进行操作?


编辑:

使用这个新见解进行更多搜索使我找到关于将回调附加到各个加载操作的信息。但是该链接中提供的类使用一个名为 LoadOperation 的对象,尽管看起来 LoadOperation 位于 System.Windows.Ria 命名空间中,但为其添加 using 不允许 Visual Studio 将对 LoadOperation 的引用识别为对象,因此我无法构建包含此类的项目。

I've been desperately trying for about the last week to figure out whatever my disconnect is that I can't wrap my head around RIA Services. I've meticulously followed the example shown in the Microsoft tutorial video and I'm still having problems. It may be that I'm trying to do something you can't, but in all likelihood I'm just going about it the wrong way.

In the tutorial they use code very similar to:

IVCContext ctx = new IVCContext();
MyDataGrid.ItemsSource = ctx.ChairOptions;
ctx.Load(ctx.GetChairOptionsQuery());

Which populates the DataGrid with the information it finds in the ChairOptions table.

But what I would like to do is have direct access to the results without having to bind them to a DataGrid, or any other control for that matter. I would like to simply get the result set, and then operate on it however I please.

More specifically, I'd like to look at it's properties (name, cost, etc) and relations (group, sub-group) that are attached to it in the model so that I can perform special actions and alter the content of controls. But it seems like no matter what I try I get a blank result set.

I've tried things like:

LocalContext ctx = new LocalContext();
var ResultSet = ctx.ChairOptions;
ctx.Load(ctx.GetChairOptionsQuery());

But ResultSet is always empty.

I feel like part of the reason I can't figure this out is because I can't seem to find out exactly what's going on in the assignment on line #2, and what the Load() function is actually doing on line #3. In the first example it just works automagically, but I'd really like to understand what's going on.

Thanks in advance for any help or references.


Edit:

It just hit me this morning as I woke up what the problem might be. Although the code makes it looks very straightforward and procedural, the Load call is actually asynchronous, right?

If that's correct, the question then becomes, how do I know when it's finished, so that I can operate on the results?


Edit:

More searching with this new insight led me to this bit of information about attaching callbacks to individual load operations. But the class provided in that link uses an object called LoadOperation, and although it appears that LoadOperation is in the System.Windows.Ria namespace, adding a using for it does not allow Visual Studio to recognize the references to LoadOperation as an object, so I can't build the project with this class in it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

━╋う一瞬間旳綻放 2024-08-29 20:05:50

这个类基本上解决了问题。它允许您指定加载操作完成时要执行的回调(以及允许您同时安排多个加载)。一旦回调被调用,我想要的数据就可用了,我可以按照我的意愿对其进行操作。

This class basically solves the problem. It allows you to specify a callback to be executed when the load operation completes (as well as allowing you to schedule multiple loads simultaneously). Once the callback is called, the data I wanted was available and I could operate on it as I pleased.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文