Load Sibling Objects

2 posts, 0 answers
  1. G. Deward
    G. Deward avatar
    9 posts
    Member since:
    Jan 2012

    Posted 03 Jun 2012 Link to this post

    How can I load RELATED objects without deep loading all child objects?  I have attached a screen shot of my tables.  My goal is query the Locale table by ID and have it load with each of the sibling objects load where the FKs that are not null.  I have the following tables:

    Continent
    Country
    State
    City
    Locale

    The first four tables are in a parent-child relationship.  The fifth table, "Locale," has FKs back to each of the other four however only ContinentID is required.  Three other FK fields (CountryID, StateID, and CityID) are all nullable.  Using the typical "LoadWith" is causing the entire hierarchy to load (essentially deep loading Country)

    // THIS IS NOT WORKING FOR ME ... TOO MANY OBJECTS ARE LOADING
    FetchStrategy fetchStrategy = new FetchStrategy();
    fetchStrategy.LoadWith<Country>(c => c.Continent);
    fetchStrategy.LoadWith<State>(c => c.Country);
    fetchStrategy.LoadWith<City>(c => c.State);


    Thank you, in advance.

    - Greg D.



  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 06 Jun 2012 Link to this post

    Hello Greg,

    I think what you want to do can be achieved if we make a change in the FetchStrategy definition.
    You can use the following code:

    FetchStrategy fetchStrategy = new FetchStrategy();
    fetchStrategy.LoadWith<Locale>(l => l.Continent);
    fetchStrategy.LoadWith<Locale>(l => l.Country);
    fetchStrategy.LoadWith<Locale>(l => l.State);
    fetchStrategy.LoadWith<Locale>(l => l.City);

    Applying the fetch strategy will enable you to get all the data in a single query and will eliminate your concerns.

    If you have any additional questions feel free to get back to us. 

    All the best,
    Viktor Zhivkov
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
Back to Top