Defining relationships

Now let's take a look at relationships between classes, and consequently between tables. There are three main types of relationships in database theory:

  • One-to-Many
  • One-to-One
  • Many-to-Many

First of all, let's define what a relationship is. It is defined based on how two or more objects relate to each other. It is identified by the multiplicity value on both ends of the relationship. For example, One-to-Many means that on one end of a relationship, sometimes called the parent, we only have one entity. On the other end of the relationship, we can have multiple entities, sometimes called children. The Entity Framework API refers to those ends as principal and dependent, respectively. The One-to-Many relationship has a slight variation, ...

Get Code-First Development with Entity Framework now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.