Manually merge DataServiceCollection RRS feed

  • Question

  • I am eager loading a group of related entities using the following "Expand" notation:

    _categories.LoadAsync(_ctx.Categories.Expand("Provisions/NewsItems, Provisions/Scenarios/User"));

    I get back a DataServiceCollection _categories, from which I can access a graph of entities through navigation properties, e.g. _categories[1].Provisions[5].Scenarios[3], etc.

    Now, Scenarios is a table in my database whose contents change regularly. I'd like to refresh the view on these scenarios in my Silverlight client, so I want to call the following... However, what I get back is a flat list of all the scenarios, regardless of association, is not accessible in any way from the graph (navigation properties) set up in the first call. 


    How can I "merge" the data received in the second load, with the graph? Should I go through each item in the flat list, and insert them into the graph in the appropriate place? If I do so, won't I be making changes to the entities, and confuse change tracking?

    On a related note, navigation properties seem only to get populated one way, e.g. _categories[1].Provisions[5] exists, but Provisions[5].category does not.

    Any ideas would be much appreciated!



    Wednesday, December 14, 2011 5:03 PM

All replies

  • HTTP is no states, there are two different request, I think you can cache the first records and the merge them. I think navigation should work as follow:


    I am fish.
    Monday, December 19, 2011 6:02 AM
  • Hi Fish,

    Thanks very much for the reply. How would I merge the records? After I call:


    I have a DataServiceCollection _scenarios that contains new scenarios. However, I can't access these new scenarios from _categories[1].Provisions[5].Scenarios, without doing something explicit on the "_categories" collection, right? This would be a merge of some sort, but I see no way to do this!


    Thanks again for your interest!



    Monday, January 9, 2012 8:56 PM
  • Hi Karl,

     Try changing the MergeOptions on the DataServiceContext instane to OverwriteChanges.
     This way, when the server returns results for a navigation property, all the values of the property on the client-side are replaced by
     values sent from the server.


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Tuesday, January 17, 2012 9:56 PM