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.
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.
In this tutorial, we look at how ASP.NET core Model Validation works. Often the data entered by the user is not valid and cannot be saved into the database. The entered data may contain a typo or user may intentionally enter the inappropriate data. Hence, we need to validate the user input before storing it in the database. The ASP.NET Core gives us Model Validator, which uses the validation attributes to validate the model, which makes our task easier. We also take a look at ModelState and how to use it. Finally, we look at the list of Validation attributes.
We are going to look at how to Configure many to many relationship in entity framework Code First in this tutorial. many to Many Relationships can be configured using Default Conventions, Data Annotations or Fluent API.