Silverlight 3 with RIA Services - Blank Result Sets/Load Finished
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开发者_Python百科 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.
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.
精彩评论