Lazy Loading Entities / Filling collections asynchronously RRS feed

  • Question

  • I have what seems like a simple problem, but I can't seem to find a solution.  Here's the scenario:

    1. I load a collection of entities from ADO.NET Data Services in Silverlight (just the top level entities), so as an example I'm just loading something like /Categories and NOT filling the collections below it (like "Books", "Music", etc).

    2. For each of the entities in the intial collection I want to fill ALL the properties of the enitity (collections) asynchronously.  So using my example, I have a collection of Categories, and now I want to fill the collections under a Category

    The second step there isn't obvious.  BeginLoadProperty only fills one, and I of course can just write a DataServiceQuery and pull the full entity and the properties back (using Expand), but now I'm pulling the main object twice.

    Ideally, I'd like to just take the full collection of Categories that came back initially and perform an Expand on the whole thing to just fill all the properties on a second go around.

    What is the proper way to accomplish it?


    Tuesday, July 21, 2009 7:38 PM

All replies

  • I'm in the same boat.  Only loaded the top level items to control time response from the server, but once I get to a detail page I need to load about three other collections of objects, and each of those objects has an object attached to it.

    Where I used to us Expand (ie.  MyTopLevelItem.Expand("FirstSubLevel1").Expand("FirstSubLevel1/SecondSubLevel1").Expand("FirstSubLevel2")

    Now I have a point where to flush out the object, I'm using LoadProperty like so:

    myDataContext.LoadProperty(myTopLevelItem, "FirstSubLevel1")
    myDataContext.LoadProperty(myTopLevelItem, "FirstSubLevel2")
    foreach aFirstSubLevel1 in myTopLevelItem.FirstSubLevel1
         myDataContext.LoadProperty(aFirstSubLevel1, "SecondSubLevel1")

    Without having a way to basically do an expand after the first get, it becomes a hassle with too many data service interactions.

    Any ideas?

    Wednesday, July 22, 2009 6:00 PM