简体   繁体   中英

Entity Framework: AsNoTracking for included child entities

If I use AsNoTracking on the top-level entity, does it get applied to all the child entities?

So for example, if I write like this

context.FirstEntity.AsNoTracking()
    .Include(f => f.ChildEntity_1)
    .ThenInclude(c => c.ChildEntity_1_1)
    .Include(f => f.ChildEntitiy_2);

Will the AsNoTracking be applied to all the child entities automatically since it is applied to the top-level entity?

Or I have to call the function separately for all the child entities too? like this

context.FirstEntity.AsNoTracking()
    .Include(f => f.ChildEntity_1).AsNoTracking()
    .ThenInclude(c => c.ChildEntity_1_1).AsNoTracking()
    .Include(f => f.ChildEntitiy_2).AsNoTracking();

AsNoTracking causes the entire query to not be tracked. This includes any child entities that might be returned by the query.

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