DbSet<T>.Local.Count not updated when calling ChangeTracker.Clear() #27750
Labels
area-change-tracking
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
While working with an application that uses the ChangeTracker to clear the unit of work I ran into strange behavior with
DbSet.Local
.After calling
context.ChangeTracker.Clear()
null
items remains inDbSet.Local
.This caught me off guard because the nullability annotations state that there can be no null items.
The minimal repro case uses a single item that is added, but if you add more entries and then clear the change tracker each entry will result in a null item.
I observed this initially with the SqlServer provider, but the repro also works with the InMemory provider.
I assume that this problem is part of the core package.
Please see the attached working repro case.
Minimal working repro
Include provider and version information
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.InMemory atleast
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 (17.1.3)
The text was updated successfully, but these errors were encountered: