Entity Framework Core Interview Question #9
What are conventions in EF Core?
EF Core Fundamentals & DbContext Junior Beginner
Quick Interview Answer
Conventions are default rules EF Core uses to build its model when explicit configuration is not provided. They cover areas such as primary keys, relationships, property mapping, and table/entity discovery.
Detailed Explanation
Conventions are default rules EF Core uses to build its model when explicit configuration is not provided. They cover areas such as primary keys, relationships, property mapping, and table/entity discovery.
Conventions reduce configuration for common designs. When the database or domain model does not follow those conventions, data annotations or Fluent API configuration can override them.
Understanding conventions helps developers know what EF Core will infer automatically and where explicit mapping is required.
Code Example
public class Blog
{
public int Id { get; set; } // Key by convention
public string Title { get; set; } = string.Empty;
}