A one-to-many relationship associates one principal entity with multiple dependent entities. In EF Core, a collection navigation property such as Book.Ratings signals that one Book can have many Rating records. section 5.2.3
A practical EF Core model uses:
- A principal entity with a collection navigation property, such as List<Rating> Ratings. section 5.2.3
- A dependent entity with a foreign key, such as Rating.BookId, and a reference navigation property, such as Rating.Book. section 5.2.3
- EF Core conventions that match BookId to Book.Id and generate the related tables and foreign keys. section 5.2.3
Persisting and loading ratings
Create a Book, add several Rating objects to its Ratings collection, add the Book to the context, and call SaveChanges. Querying with Include(b => b.Ratings) loads each book together with its ratings for display. section 5.2.3
Listing 5.9 One-to-many relationship with Book as the parent and Rating as the child
class Book {
public int Id {get;set;}
public List<Rating> Ratings
{get;}
}
class Rating
{
public int Id {get;set;}
public int BookId {get;set;}
public Book Book {get;}
}
The focused entity listing shows the principal collection, dependent foreign key, and navigation property together. section 5.2.3











