liveBook · Manning

Ef core convention

As explained in Building Web APIs with ASP.NET Core

An Entity Framework Core convention is a built-in naming or modeling rule that automatically maps entity structures to database schema elements.

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

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines conventions and their precedence but stops short of detailing individual naming rules.
Examples
Uses an ApplicationDbContext skeleton and contrasts convention-based mapping with annotated entity classes.
What it assumes
Assumes familiarity with C# classes and DbContext while introducing EF Core configuration approaches.
What you can do after
Apply conventions when possible to reduce explicit EF Core model configuration.
How it connects
Connects conventions with DbContext, data annotations, Fluent API, ModelBuilder, and database schema mapping.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.