Relationships in Entity Framework Core
Explore how to configure and understand relationships in Entity Framework Core. This lesson covers principal and dependent entities, navigation properties, foreign keys, and different relationship types. Learn how these concepts define the way entities interact and map to database tables, enhancing your data model and application design.
Overview
In EF Core, relationships define how two entities relate and how the database reflects the relationship. When dealing with relational databases, EF Core uses foreign keys to establish the relationships between entities. This lesson introduces the concepts surrounding the relationship between entities.
The code sample below illustrates some concepts regarding relationships in EF Core:
The code sample illustrates the relationship between the Employee and Album entities. It highlights the following concepts:
-
Dependent entity: This is the entity that contains the foreign key properties. It is also known as the child of the relationship. The
Albumentity is the dependent entity in the code sample. Line 9 ofAlbum.cshighlights a foreign key, and line 10 contains a reference navigation property to the ...