Mastering Entity Framework Core: A Comprehensive Guide to Code-First Development—2

yusuf sarıkaya
10 min readJun 16, 2024

We will proceed with EFCore using Code first, mapping your model to the database. In this article, we will cover two different related topics: keys and relationships. Since keys ensure each record in database is unique, while relationships define how models are connected with each other. Initially, I planned to proceed with only relationships, but understanding keys is essential before delve into relationships. As far as the keys are fundamental to establishing relationships, you will see keys in this article.

Before we begin, it’s important to note that in this article series, we’ll be using the model builder(also known as Fluent API) rather than using mapping attributes(also know as data annotation)

You can take a look at the previous article in this series:
Article 1: Mastering Entity Framework Core: A Comprehensive Guide to Code-First Development — 1

What is The Relationship in EF Core?

In object-oriented programming, each class is designed to represent specific data structure and real-world entity make it easier to write complex software. However, in the real- world, most objects are related to each other. For example, lets assume we have a brand that produces car. This brand…

--

--