Entity Framework Core Interview Question #170

What are backing fields in EF Core?

Advanced Mapping, Interceptors, Value Conversions & Architecture Senior Advanced

Quick Interview Answer

Backing fields allow EF Core to persist data through fields rather than requiring public property setters. This supports encapsulated domain models where state changes occur through methods. EF Core can discover some conventional backing-field names or fields can be configured explicitly.

Detailed Explanation

Backing fields allow EF Core to persist data through fields rather than requiring public property setters. This supports encapsulated domain models where state changes occur through methods. EF Core can discover some conventional backing-field names or fields can be configured explicitly.

Code Example

modelBuilder.Entity<Account>()
    .Property(a => a.Balance)
    .HasField("_balance");