Configuring the mapping between models and database
ORM, as the name suggests, is used to map the objects to the relational database. EF Core uses the mapping configuration to map the models to the database. In the previous section, we saw that we did not configure any mappings; however, EF Core could still map the models to the database automatically. This is because EF Core has a set of built-in conventions to configure the mappings. We can also explicitly customize the configuration to meet our needs. In this section, we will discuss the configuration in EF Core, including the following:
- Mapping conventions
- Data annotations
- Fluent API
Mapping conventions
There are some conventions in EF Core for mapping the models to the database:
- The database uses the
dbo
schema by default. - The table name is the plural form of the model name. For example, we have a
DbSet<Invoice> Invoices
property in theInvoiceDbContext
class, so the table name isInvoices...