Change tracking

From dotnet/efcore · View interactive version

Change tracking is an AI agent skill from the GitHub repository dotnet/efcore. Implementation details for EF Core change tracking. Use when changing InternalEntityEntry, ChangeDetector, SnapshotFactoryFactory, or related entity state, snapshot, or property accessor code.

How to use this skill

Skill file

Change Tracking

Manages entity states and detects changes for SaveChanges().

Core Components

Change Detection

Shared-Identity Replacement

SharedIdentityEntry is the invariant that distinguishes an old deleted entry from its replacement with the same identity. When attaching a replacement graph, a deleted nested entry should be reconsidered only when its source entry has a replacement; do not broadly process every deleted node. Likewise, cascading from the old replaced principal must not delete dependents that belong to the replacement graph. Keep synchronous and asynchronous graph-attach paths equivalent and preserve unrelated values in replacement tests so they isolate the identity transition.

Testing

Unit tests: test/EFCore.Tests/ChangeTracking/. Functional tests: test/EFCore.Specification.Tests/GraphUpdates/.

Common Pitfalls

| Pitfall | Solution |

|---------|----------|

| State-based checks treat every Added/Deleted entry as a replacement | Scope replacement behavior through SharedIdentityEntry and the graph source |

Validation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.