Entity Framework Core Interview Question #169

What are shadow properties useful for in advanced EF Core models?

Advanced Mapping, Interceptors, Value Conversions & Architecture Senior Advanced

Quick Interview Answer

Shadow properties exist in the EF Core model without corresponding CLR properties. They can hold persistence-only values such as foreign keys, audit metadata, or legacy columns while keeping them out of the domain class. They are accessed through Entry APIs or EF.Property in queries. Excessive use can make the model harder to discover and maintain.

Detailed Explanation

Shadow properties exist in the EF Core model without corresponding CLR properties. They can hold persistence-only values such as foreign keys, audit metadata, or legacy columns while keeping them out of the domain class. They are accessed through Entry APIs or EF.Property in queries. Excessive use can make the model harder to discover and maintain.

Code Example

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

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