[英]AsNoTracking() and Include
I have a Linq query that fetches an entity and some of its navigation properties. 我有一个Linq查询,用于获取实体及其某些导航属性。
context.MyEntity
.AsNoTracking()
.Include(i=> i.Nav1)
.Include(i=> i.Nav2)
.Where(x=> x.Prop1==1)
.FirstOrDefault();
my question is: 我的问题是:
Is the above query enough to not track MyEntity
nor the navigation properties NAv1
& Nav2
or must I add AsNoTracking
for each navigation property? 以上查询是否足以不跟踪MyEntity
和导航属性NAv1
和Nav2
还是必须为每个导航属性添加AsNoTracking
?
like this: 像这样:
context.MyEntity
.AsNoTracking()
.Include(i=> i.Nav1)
.AsNoTracking()
.Include(i=> i.Nav2)
.AsNoTracking()
.Where(x=> x.Prop1==1)
.FirstOrDefault();
Use AsNoTracking after you have completed all your query parameters but before you move the data into memory. 在完成所有查询参数之后但在将数据移动到内存之前使用AsNoTracking。 In this example, you'll want: 在此示例中,您将需要:
context.MyEntity
.Include(i=> i.Nav1)
.Include(i=> i.Nav2)
.Where(x=> x.Prop1==1)
.AsNoTracking()
.FirstOrDefault();
Any child objects of the parent entity will not be tracked. 不会跟踪父实体的任何子对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.