I am trying to get a table from database using entity framework.
The table has reference to other table which again has reference to other tables. I know how to include other tables. And according to this answer and this MSDN page including multiple levels are like this:
entity.TableLevel1.Include(tLvl1=>tLvl1.TableLevel2.Select(tLvl2=>tLvl2.TableLevel3));
But my question is, how to include another table at level 3 ?
This seems not to work:
entity.TableLevel1
.Include(tLvl1=>tLvl1.TableLevel2
.Select(tLvl2=>tLvl2.TableLevel3)
.Select(tLvl2 => tLvl2.AnotherTableLevel3);
Add another Include
call:
entity.TableLevel1.Include(tLvl1=>tLvl1.TableLevel2.Select(tLvl2=>tLvl2.TableLevel3))
.Include(tLvl1=>tLvl1.TableLevel2.Select(tLvl2=>tLvl2.AnotherTableLevel3));
If you want to load related entities that are at the same level you should call Include
extension method for each of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With