简体   繁体   English

EF Include()与AsNoTracking

[英]EF Include() with AsNoTracking

I have this linq query: 我有这个linq查询:

database.EmployeeHistory.AsNoTracking()
.Include("Employee.Orders")
.Include("Employee.Books").AsNoTracking()

This works except that saving the changes I made for Employee.Orders is not working. 除了保存我为Employee.Orders所做的更改不起作用之外,这个工作正常。 Does this means that even I did not add the AsNoTracking for Employee.Orders it is also not tracked? 这是否意味着即使我没有为Employee.Orders添加AsNoTracking它也没有被跟踪?

AsNoTracking means that any changes you make to the entity(s) are not tracked by the change tracker and will not be picked up when you call SaveChanges(). AsNoTracking意味着您对实体所做的任何更改都不会被更改跟踪器跟踪,并且在您调用SaveChanges()时不会被选中。

AsNoTracking() is meant for read-only scenarios. AsNoTracking()用于只读方案。 In this case, your entities are not tracked by the context and should help with memory usage & performance. 在这种情况下,您的实体不会被上下文跟踪,并且应该有助于内存使用和性能。

In your case, remove AsNoTracking() and try to save again. 在您的情况下,删除AsNoTracking()并尝试再次保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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