An EF Core convention is a built-in naming standard that maps model structures to database schema elements automatically, without Fluent API or data annotations. section 4.3.3
EF Core provides three model-configuration approaches:
- Conventions supply default mapping rules. section 4.3.3
- Data annotations add entity-specific metadata and override conventions. section 4.3.3
- The Fluent API configures models through ModelBuilder and overrides both alternatives. section 4.3.3
Listing 4.1 ApplicationDbContext.cs file
using Microsoft.EntityFrameworkCore;
namespace MyBGList.Models
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(
DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// TODO: custom code here
}
}
}
Use the DbContext skeleton as the starting point for convention-based EF Core model configuration. section 4.3.3
