Skip to content

Commit 781e80a

Browse files
committed
Unblock ExecuteUpdate column-self-reference EF Core tests: not a simulator gap — ExecuteUpdate bypasses the change tracker, but the verification queries used context.Users.Single(...) which returns the tracked entity (cached from the initial AddRange/SaveChanges) with the stale pre-update value. Changed verifications to AsNoTracking().Single() so the identity-map shortcut doesn't surface stale data. The literal-value sibling test masked the same pattern by verifying via .Sum(), which is an aggregate query that always hits the DB. Probe-confirmed the simulator's UPDATE [u] SET [u].[col] = [u].[col] + 1 FROM [Users] AS [u] WHERE … path was already correct — EF's exact emitted SQL works end-to-end through a raw connection.
1 parent b34392c commit 781e80a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

SqlServerSimulator.Tests.EFCore/EFCoreExecuteUpdateDelete.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ public void ExecuteUpdate_SetsLiteralValue()
8989
}
9090

9191
[TestMethod]
92-
[Ignore("Needs: ExecuteUpdate column-self-reference")]
9392
public void ExecuteUpdate_SetsComputedExpression()
9493
{
9594
using var context = SeededContext();
9695
var affected = context.Users
9796
.Where(u => u.Active)
9897
.ExecuteUpdate(s => s.SetProperty(u => u.LoginCount, u => u.LoginCount + 1));
9998
Assert.AreEqual(2, affected);
100-
Assert.AreEqual(4, context.Users.Single(u => u.Id == 1).LoginCount);
101-
Assert.AreEqual(8, context.Users.Single(u => u.Id == 3).LoginCount);
99+
// ExecuteUpdate bypasses the change tracker — verify via AsNoTracking()
100+
// so the identity map doesn't return the stale pre-update entity.
101+
Assert.AreEqual(4, context.Users.AsNoTracking().Single(u => u.Id == 1).LoginCount);
102+
Assert.AreEqual(8, context.Users.AsNoTracking().Single(u => u.Id == 3).LoginCount);
102103
}
103104

104105
[TestMethod]
105-
[Ignore("Needs: ExecuteUpdate column-self-reference")]
106106
public void ExecuteUpdate_MultipleSetProperty()
107107
{
108108
using var context = SeededContext();
@@ -112,7 +112,7 @@ public void ExecuteUpdate_MultipleSetProperty()
112112
.SetProperty(u => u.Name, u => u.Name + "!")
113113
.SetProperty(u => u.LoginCount, u => u.LoginCount + 10));
114114
Assert.AreEqual(1, affected);
115-
var alice = context.Users.Single(u => u.Id == 1);
115+
var alice = context.Users.AsNoTracking().Single(u => u.Id == 1);
116116
Assert.AreEqual("alice!", alice.Name);
117117
Assert.AreEqual(13, alice.LoginCount);
118118
}

0 commit comments

Comments
 (0)