LINQ to SQL LoadWith Mutilple Joins
I have the following table structure....
- Pilots
- Operators
- Ranks
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 ge开发者_JAVA百科t 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.
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.
精彩评论