change-tracking
dotnet/efcore/.agents/skills/change-tracking/SKILL.md
Implementation details for EF Core change tracking. Use when changing InternalEntityEntry, ChangeDetector, SnapshotFactoryFactory, or related entity state, snapshot, or property accessor code.
Skill15k starsChanged today
What's in it
- Change Tracking
- Core Components
- Change Detection
- Shared-Identity Replacement
- Testing
- Common Pitfalls
- Validation
--- name: change-tracking description: 'Implementation details for EF Core change tracking. Use when changing InternalEntityEntry, ChangeDetector, SnapshotFactoryFactory, or related entity state, snapshot, or property accessor code.' user-invocable: false --- # Change Tracking Manages entity states and detects changes for `SaveChanges()`. ## Core Components - `StateManager` — owns tracked entries, identity/reference maps, fixup, cascades, notifications, and changed counts - `InternalEntryBase` and derived classes — own per-entry state, flags, values, snapshots, and ordered state transitions - `ChangeDetector` — compares current values with baselines and reports changes through entry mutation APIs - `SnapshotFactoryFactory` subclasses — create passive original- and relationship-value baselines - `IdentityMap` — permits one active entry per key; shared identity pairs a replacement with the prior `Deleted` entry - `PropertyAccessorsFactory`, `ClrPropertyGetterFactory` and `ClrPropertySetterFactory` compile property accessors for efficient snapshotting and change detection - Ordinals in `indices` parameter specify element at each complex collection depth ## Change Detection - Snapshot and notification strategies both call `SetPropertyModified()` to keep property flags and entity state consistent. - `SetEntityState()` validates values, updates flags and complex entries, changes state, then runs manager bookkeeping hooks. ## 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 - `DetectChanges()` identifies modified properties via snapshot comparison - Setting original values marks properties as modified or unchanged based on comparison with current values
More agent context in dotnet/efcore
16 other files this repository gives its agents.
Copilot instructions
Skill
- code-review.agents/skills/code-review/SKILL.md
- cosmos-provider.agents/skills/cosmos-provider/SKILL.md
- make-custom-agent.agents/skills/make-custom-agent/SKILL.md
- make-github-actions-workflow.agents/skills/make-github-actions-workflow/SKILL.md
- make-instructions.agents/skills/make-instructions/SKILL.md
- make-skill.agents/skills/make-skill/SKILL.md
- migrations.agents/skills/migrations/SKILL.md
- model-building.agents/skills/model-building/SKILL.md
- run-apichief.agents/skills/run-apichief/SKILL.md
- scaffolding.agents/skills/scaffolding/SKILL.md
- servicing-pr.agents/skills/servicing-pr/SKILL.md
- sqlite-adonet.agents/skills/sqlite-adonet/SKILL.md
- tooling.agents/skills/tooling/SKILL.md
- triage.agents/skills/triage/SKILL.md
- update-pipeline.agents/skills/update-pipeline/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

