Entity Framework Core Interview Question #87
How do you configure table and column names in EF Core?
Migrations, Database Schema & Data Management Mid-Level Intermediate
Quick Interview Answer
EF Core can map entity types and properties to specific table and column names using data annotations or the Fluent API.
Detailed Explanation
EF Core can map entity types and properties to specific table and column names using data annotations or the Fluent API.
Explicit mapping is useful when working with an existing database naming convention or when CLR names should differ from physical schema names.
Changing a mapped table or column name can cause a generated migration to interpret the change as drop-and-create unless the migration is reviewed and adjusted to preserve existing data.
Code Example
modelBuilder.Entity<Product>(entity =>
{
entity.ToTable("CatalogProducts");
entity.Property(p => p.Name)
.HasColumnName("ProductName");
});