Defining EF Core Models
Learn about the ways to define a model in Entity Framework (EF) Core: using conventions, annotation attributes, and the Fluent API.
EF Core uses a combination of conventions, annotation attributes, and Fluent API statements to build an entity model at runtime so that any actions performed on the classes can be automatically translated into actions performed on the actual database. An entity class represents the structure of a table, and an instance of the class represents a row in that table.
Ways to define a model
First, we will review the three ways to define a model, with code examples, and then we will create some classes that implement those techniques.
Using EF Core conventions to define the model
The code we will write will use the following conventions:
The name of a table is assumed to match the name of a
DbSet
property in theDbContext
...