Skip to content
Back to skills

Change Tracking

ASecurity

Implementation details for EF Core change tracking. Use when changing InternalEntityEntry, ChangeDetector, SnapshotFactoryFactory, or related entity state, snapshot, or property accessor code.

  • 14,795 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 5, 2026
databasestestingapi

Works with

  • api

Security analysis

A100/100

Scanned September 20, 2026

npx -y skills add dotnet/efcore --skill change-tracking --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Change Tracking?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Change Tracking
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/dotnet-change-tracking/badge)](https://www.skillsdirectory.com/skills/dotnet-change-tracking)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.

## Testing

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

## Common Pitfalls

| Pitfall | Solution |
|---------|----------|
| There is a failure when there is shared identity entry (Added and Deleted) | Add code that checks `SharedIdentityEntry` |

## Validation

- `DetectChanges()` identifies modified properties via snapshot comparison
- Setting original values marks properties as modified or unchanged based on comparison with current values

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.