change-tracking

Describe EF Core change tracking with DetectChanges, snapshots, and entity states.

14.8k|3.4k|Updated Jan 23, 2014
One-click install
npx skills add https://github.com/dotnet/efcore --skill change-tracking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: change-tracking
Source: https://github.com/dotnet/efcore/tree/main/.agents/skills/change-tracking
Command: npx skills add https://github.com/dotnet/efcore --skill change-tracking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

EF Core's change-tracking subsystem ensures accurate detection of modified properties and proper state management during SaveChanges.

Core Features & Use Cases

  • Centralizes logic for tracking entity states, detecting changes, and generating snapshots.
  • Documents components such as StateManager, InternalEntityEntry, ChangeDetector, and SnapshotFactoryFactory used in change detection and persistence.
  • Supports debugging and extending EF Core's change-tracking pipeline in complex scenarios.

Quick Start

Configure and wire the Change Tracker components (StateManager, InternalEntityEntry, ChangeDetector, SnapshotFactoryFactory) to enable accurate change detection and snapshotting during SaveChanges.

Frequently Asked Questions about change-tracking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does EF Core change tracking detect modified properties during SaveChanges?

EF Core change tracking detects modified properties during SaveChanges by utilizing the ChangeDetector to compare current entity values against generated snapshots. The StateManager and InternalEntityEntry components track these differences to ensure accurate state management and persistence.

What is the role of snapshot generation in EF Core entity state management?

Snapshot generation in EF Core entity state management captures the original values of entities upon loading. The SnapshotFactoryFactory creates these snapshots, allowing the ChangeDetector to identify exactly which properties have been modified before executing SaveChanges.

How do I configure EF Core change tracking components for my application?

To configure EF Core change tracking components, you wire the StateManager, InternalEntityEntry, ChangeDetector, and SnapshotFactoryFactory together. This setup enables accurate change detection, original value handling, and snapshotting during SaveChanges operations.

Why does DetectChanges not capture my entity updates in EF Core?

DetectChanges might not capture entity updates if the snapshot generation or InternalEntityEntry state management is improperly configured. Verifying that the ChangeDetector correctly compares original values against current entity properties ensures accurate change detection.

Can I debug EF Core's change-tracking pipeline for complex scenarios?

Yes, you can debug EF Core's change-tracking pipeline for complex scenarios. The Skill documents the internal components like StateManager, InternalEntityEntry, ChangeDetector, and SnapshotFactoryFactory to support debugging and extending the change detection logic.