Entity Framework Core Interview Question #48

What are shadow properties in EF Core?

Relationships, Navigation Properties & Loading Data Junior Beginner

Quick Interview Answer

A shadow property exists in the EF Core model but not as a CLR property on the entity class. EF Core stores its value in the change tracker.

Detailed Explanation

A shadow property exists in the EF Core model but not as a CLR property on the entity class. EF Core stores its value in the change tracker.

Shadow foreign keys can be created when a relationship needs a foreign key but the entity class does not expose one explicitly. Shadow properties can also be configured intentionally for metadata.

They can keep persistence details out of domain classes, but explicit properties are often easier to work with in disconnected ASP.NET Core scenarios.

Code Example

modelBuilder.Entity<Post>()
    .Property<DateTime>("LastUpdatedUtc");

var query = db.Posts
    .Where(p => EF.Property<DateTime>(
        p, "LastUpdatedUtc") > cutoff);