我使用EF5,并且不知道为什么一个实体在将该实体的唯一更改的PropertyValue设置回原始值之后具有“修改”状态.
using (TestDbContext context = new TestDbContext()) { string name = context.Person.First().Name; // count is 0 int count = context.ChangeTracker.Entries().Count(e => e.State == EntityState.Modified); // Change Value context.Person.First().Name = "Test"; // count is 1 count = context.ChangeTracker.Entries().Count(e => e.State == EntityState.Modified); // Revert Value context.Person.First().Name = name; context.ChangeTracker.DetectChanges(); // count is 1 count = context.ChangeTracker.Entries().Count(e => e.State == EntityState.Modified); }
为什么? 原文链接:https://www.f2er.com/csharp/93325.html