In this tutorial, we will learn how to Configure One to Many relationships in Entity Framework Core. You can use EF Core Conventions, Data Annotations or Fluent API to configure the One to Many relationships.
EF Core Conventions
We are going to look at how to Configure one to one relationship in entity framework core using Convention, Data Annotations & Fluent API.
In relational databases, it is a healthy practice to divide the data between related tables. For Example, the employee working in a particular department. We do not store both the information in the same table but divide them into Employee & Department table. When we divide tables, we also need to specify the relationships between them. For example, if you are looking for an employee working in a particular department, then you need to specify the relationship between employees and the department table. The relationship between these tables is defined using the foreign keys. We then use these relationships to query the database to get the meaningful data.
EF Core Conventions or the default rules that you follow while creating the entity model. The EF Core uses these to infer and to configure the Database. It uses the information available in the POCO Classes to determine and infer the schema of the database that these classes are mapped to. For example, the table name, Column Name, Data Type, Primary keys are inferred from the Class name, property name & Property type by convention to build the database