This is a migrated thread and some comments may be shown as answers.

Load Sibling Objects

1 Answer 53 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
G. Deward
Top achievements
Rank 1
G. Deward asked on 03 Jun 2012, 05:01 PM
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.



1 Answer, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 06 Jun 2012, 05:09 PM
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!
Tags
Getting Started
Asked by
G. Deward
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Share this question
or