添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account public int C1Id { get; set; } public int C2Id { get; set; } public virtual C C1 { get; set; } public virtual C C2 { get; set; } public class C public int Id { get; set; }

Now suppose I want to retrieve all A 's and include their B 's and both of B 's C sub-properties.

I can do db.A.Include(a => a.B).ThenInclude(b => b.C1) to include one of B 's C sub-properties, but as far as I can tell, there's no way to include both of B 's C sub-properties. If I tack on another .Include() , I'm dealing with A 's. If I tack on anther .ThenInclude() , I'm now dealing with C 's. There's no way to deal with B 's beyond the first call to .ThenInclude() .

I propose that the IIncludableQueryable interface should also expose an .AndInclude() method, which can be tacked onto a call to .ThenInclude() to continue accessing the associated property.

.Include(a => a.B).ThenInclude(b => b.C2)

BTW because these are reference (and not collection) properties, you can do this for short. ThenInclude only becomes mandatory when you want to include after a collection navigation property.

.Include(a => a.B.C1) .Include(a => a.B.C2) feO2x, funkyOne, karlssonsimon, dstep2007, spottedmahn, conterio, KirkEvans, jasonsturges, wdehaes, ch-hristov, and 128 more reacted with thumbs up emoji ddyrcz, vladiliescu, courosh12, divieirasilva, CRodriguez25, JojoJgeorge, WashingtonARamos, MassiStudent, spapaseit, Kurdran, and 13 more reacted with hooray emoji rambhual, neooleg, suadev, ShawnTheBeachy, ewaschenko, Riaan-Crause-Kohde, aschuhardt, eltiare, courosh12, VJalili, and 6 more reacted with confused emoji ceelsoin, pfrozi, marc-wilson, UthpalaBandara, AskYous, ryan-allen, thargenediad, gayancc, dominikkoziol, jmoralesv, and 5 more reacted with heart emoji NArtemev, austindrenski, LeszekKalibrate, Wenfengcheng, tmsbrndz, and jarmatys reacted with rocket emoji All reactions

Is there any restriction on how deep you can go with ThenInclude ?
Because up to level three ( Info )everything works fine. When I include level four ( Details ) it is not returned or included as an object.

Company company = _context.Companies
                 .Include(c => c.Users)
                 .Include(c => c.Projects)
                     .ThenInclude(p => p.Specifications)
                        .ThenInclude(spec => spec.Info)
                            .ThenInclude(info => info.Details)
                 .Include(c => c.Projects)
                     .ThenInclude(p => p.Specifications)
                        .ThenInclude(spec => spec.Files)
                .Where(t => t.CompanyId.Equals(companyId))
                 .FirstOrDefault();

The details objects are missing in the query and not returned. Any idea?

ashahabov, itsmecurtis, johncrisostomo, dochal, AETSTUDIO, andjiev, EmanuelDavid, MisterJimson, divieirasilva, nttai9319, and 12 more reacted with thumbs up emoji sergej-kodit reacted with heart emoji All reactions

it would be great this substitute syntax instead of repeat one thing consecutively
return _cart .Include(x => x.GameItems) .ThenInclude(x=>x.Game) .ThenInclude(x=>new{x.League,x.Host,x.Guest}) .AsQueryable();

instead of
return _cart
.Include(x => x.GameItems)
.ThenInclude(x=>x.Game)
.ThenInclude(x=>x.League)

            .Include(x => x.GameItems)
            .ThenInclude(x=>x.Game)
            .ThenInclude(x=>x.Host)
            .Include(x => x.GameItems)
            .ThenInclude(x=>x.Game)
            .ThenInclude(x=>x.Guest)
            .AsQueryable();
it's more comprehensible and shorter and easier

After doing this how exactly would I get a where condition from either C1 or C2? seems not to work when I try it with my repository pattern and EF6. Any leads here?

db.A .Include(a => a.B.C1) .Include(a => a.B.C2)

include theinclude both works fine... b ut only problem is intellisense not identifying or showing the methods just type and then proceed all works fine ...
var res = await _context.Diseases.Include(x => x.Disease2Symptom) .ThenInclude(z => z.Symptom).ToListAsync();

include theinclude both works fine... b ut only problem is intellisense not identifying or showing the methods just type and then proceed all works fine ...
var res = await _context.Diseases.Include(x => x.Disease2Symptom) .ThenInclude(z => z.Symptom).ToListAsync();

Thanks. It took me a long time to realize that what I was trying to do was perfectly valid but that it just wasn't showing in intellisense. I should have just typed it anyway.

Example:
intellisense works fine here:

from q in db.SecurityGroupPermissions
    .Include(x => x.SecurityAction)

intellisense does not work on the last item here. A list will pop up but it won't have SecurityAction in the popup:

from q in db.SecurityGroups
    .Include(x => x.SecurityGroupPermissions)
    .ThenInclude(x => x.SecurityAction)

Once I ignored intellisense and typed it out anyway then it built and ran correctly.

JLance14, AdamDiament, jeangatto, ScholliYT, jmoralesv, m-ermolaev, tedchirvasiu, miltonhowe, suadev, CleytonGoncalves, and 64 more reacted with thumbs up emoji aleksa-kuzman, annerajb, and arunthomasarun reacted with confused emoji a-patel, AdamDiament, jmoralesv, jupjohn, m-ermolaev, DanielFalzon, K20shores, Farami, AlexVPerl, TheEskhaton, and 17 more reacted with eyes emoji All reactions gergo123, rafaelgianine, ddegasperi, BassFaceIV, Uraharadono, GorganGabi, sorensenmarius, Elip-tdlr, andDaviD, fernandobracaroto, and 24 more reacted with thumbs up emoji arunthomasarun, ohnv, martijnhoekstra, kobynz, and rgwebb reacted with confused emoji arunthomasarun, rgwebb, and Ignisz reacted with eyes emoji All reactions

@Uraharadono only 22 lines of code? I just wrote one with 45 lines of Include() and ThenInclude() chaining. Admittedly, each on a new line for readability.

I thought that there surely must be a better way by now but alas!

Any news whether "Include.ThenInclude.AlsoInclude" syntax or similar will be implemented for a more elegant solution to this problem?

Why is this closed without any follow up?