I’m starting to use a Silverlight WCF RIA Domain Services and I have one question.
So far I was able to fill a DataGrid with data coming from my WCF. This is alright.
But I’d like to simply get a list of, let’s say, all my users. Normally with the DataGrid I’d do:
CortexDomainContext oContext = new CortexDomainContext();
this.dataGrid1.ItemsSource = oContext.Users;
oContext.Load(oContext.GetUsersQuery());
But if I only want to get a List of the result, how must I do it?!
I tried:
List<User> oUsers = oContext.Users.ToList();
oContext.Load(oContext.GetUsersQuery());
But it didn’t worked.
Everything is working alright but this question still remains in my mind…
Thanks a lot!
DomainContext.Loadis asynchronous as any other web call in Silverlight, therefore you get the results either via a callback, or via an event handler. Examples:via callback, see http://msdn.microsoft.com/en-us/library/ff422945(v=vs.91).aspx
via event handler, see http://msdn.microsoft.com/en-us/library/ff422589(v=VS.91).aspx
I would recommend the first way.
The
DataGridworks without it because it binds to an entityset which implementsINotifyCollectionChanged, i.e. notifies subscribers when an entity is added to or removed from the entityset. TheDataGrid(in fact, theItemsControl) subscribes to theINotifyCollectionChanged.CollectionChangedevent to track the entityset modifications.