简体   繁体   中英

How to include multiple child into Query?

I have table A, B , C, D, E, F with the relationship
A(parent) --> B ---> C (Part A) A(parent) --> D --> E -- > F (Part B)

I'd refer the link below to get my answer but I am only able to get till E part B. I couldn't get until F

Click here !

Here is my code:

var query = db.tableA.Include(c => c.tableB.Select(b => b.tableC))                                                                                 
           .Include(d => d.tableD.Select(e => e.tableE));

It one tableE can have collection of tableF then you just need to add another select:

var query = db.tableA.Include(c => c.tableB.Select(b => b.tableC))
        .Include(d => d.tableD.Select(e => e.tableE.Select(m => m.tableF)));

If one tableE can have one tableF then you should write it as below:

var query = db.tableA.Include(c => c.tableB.Select(b => b.tableC))
        .Include(d => d.tableD.Select(e => e.tableE.tableF));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM