Remotec
Remotec

Reputation: 10758

LINQ to SQL LoadWith Mutilple Joins

I have the following table structure....

Pilots/Operations - there are multiple pilots to one operator.

Ranks: 1) Captain 2) First Officer

Each operator then defines its own rank criteria (hours required etc).

So to get the actual name of the rank I need to join from Pilots -> Operators -> Ranks.

I would like to do this with LoadWith e.g.

options.LoadWith<Pilot>(x => x.Operator);

How to now make it also eager load the ranks? The above statement only causes a join to Operators.

Thanks.

Upvotes: 2

Views: 896

Answers (1)

dexter
dexter

Reputation: 7203

If you want to go down the differed loading path, than you would do the same for your Ranks:

 options.LoadWith<Pilot>(x => x.Operator);
 options.LoadWith<Operators>(y=>y.Rank);
 yourDataContext.LoadOptions = options;

Then you can also always do the join with linq as well as the LoadOptions is known to produce very inefficient queries.

Upvotes: 3

Related Questions