首页 > 其他 > 详细

ef 实体跟踪的函数

时间:2020-11-21 22:47:05      阅读:36      评论:0      收藏:0      [点我收藏+]

xxx.Find()
xxx.First()
xxx.ToArray()
...

 

https://www.zhihu.com/question/388290065

 

Entity Framework Code First中能够自动调用DbContext.ChangeTracker.DetectChanges的方法:

  ? DbSet.Add

  ? DbSet.Find

  ? DbSet.Remove

  ? DbSet.Attach

  ? DbSet.Local

  ? DbContext.SaveChanges

  ? DbContext.GetValidationErrors

  ? DbContext.Entry

  ? DbChangeTracker.Entries

  ? 任何在DbSet上进行LINQ的查询

https://blog.csdn.net/u011127019/article/details/53941235

 

同一个上下文中,更新时,同一实体只能跟踪一次,如果再次获取该对象并且跟踪,并更新该对象时就会报错,因为ef无法确定具体那个跟踪的对象需要被保存,错误如下

The instance of entity type ‘UserEntity‘ cannot be tracked because another instance with the same key value for {‘Id‘} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using ‘DbContextOptionsBuilder.EnableSensitiveDataLogging‘ to see the conflicting key values

 

https://q.cnblogs.com/q/103473/  此问题中就是Find会跟踪对象,导致更新失败

ef 实体跟踪的函数

原文:https://www.cnblogs.com/slyzly/p/14016822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!