What is a shadow property in EF Core?

Entity Framework & EF Core Modelling Advanced 3–5 Yrs5+ Yrs Conceptual 1 min read

Quick Answer

A shadow property exists in the EF Core model and the database column but not as a property on your entity class. EF creates them automatically for conventional foreign keys, and you can add your own — e.g. audit columns like LastModified — without polluting the domain model. You read/write them via EF.Property<T>(entity, "Name") or in SaveChanges.

A shadow property is a column EF knows about and maps to the database, but that isn't a property on the C# class. EF creates them for you when a foreign key isn't declared on the entity. Where I use my own is audit fields — LastModified, CreatedBy — so the database has the column and EF tracks it, but the domain entity stays clean. I set them in one place by overriding SaveChanges and iterating the change tracker entries, and I read them with EF.Property.

  • Auto-created: if Order has an Customer navigation but no CustomerId property, EF adds a shadow CustomerId.
  • Configure: modelBuilder.Entity<Order>().Property<DateTime>("LastModified");.
  • Set them centrally in an overridden SaveChanges: loop ChangeTracker.Entries() and set entry.Property("LastModified").CurrentValue = ....
  • Great for cross-cutting audit fields the domain shouldn't know about.