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

Deep Load Child Objects

2 Answers 81 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 19 Jan 2012, 12:26 AM
How can I deep load parent-child objects?  For example, if I have Country, State, and City tables, how I can I load all Countries and all States for all Countries and all Cities for all States?  I have played with ORM for over a day now and cannot figure it out.  I do not know if this is a LINQ question or ORM question.

Thank you -
- Greg D. 

2 Answers, 1 is accepted

Sort by
0
G. Deward
Top achievements
Rank 1
answered on 19 Jan 2012, 01:30 AM
I have tried the following without any success:

            using (var entities = new GlobalResourcesEntities())

            {

                FetchStrategy fetchStrategy = new FetchStrategy();

                fetchStrategy.LoadWith<State>(c => c.Country);

                fetchStrategy.LoadWith<City>(c => c.State);

                //fetchStrategy.LoadWith<State>(c => c.CountryID);

                //fetchStrategy.LoadWith<City>(c => c.StateID);

                entities.FetchStrategy = fetchStrategy;

                try

                {

                    var countries = entities.Countries.ToList();

                    foreach (var country in countries)

                    {

                        Console.WriteLine(country.CountryName);

                    }

                }

                catch (Exception ex) { Console.WriteLine(ex.Message); }

            }

0
Ralph Waldenmaier
Telerik team
answered on 19 Jan 2012, 01:44 PM
Hello Greg,

The provided code snippet looks good and should load all the State objects when you query the Countries. This is nearly the same scenario as described in our documentation.
But from the information you provided, I can not see where an error occurs. Which error did you get? What exactly is not working in your setup? Did you look into a log file in order to check whether the expected sql statement is fired? 

I am looking forward to hearing from you soon in order to get this solved for you.

Regards,
Ralph
the Telerik team

SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

Tags
Getting Started
Asked by
G. Deward
Top achievements
Rank 1
Answers by
G. Deward
Top achievements
Rank 1
Ralph Waldenmaier
Telerik team
Share this question
or