8 Configuring relationships

 

This chapter covers

  • Configuring relationships with By Convention
  • Configuring relationships with Data Annotations
  • Configuring relationships with the Fluent API
  • Mapping entities to database tables in five other ways

Chapter 7 described how to configure scalar (nonrelational) properties. This chapter covers how to configure database relationships. I assume that you’ve read at least the first part of chapter 7, because configuring relationships uses the same three approaches—By Convention, Data Annotations, and the Fluent API—to map the database relationships.

This chapter covers how EF Core finds and configures relationships between entity classes, with pointers and examples showing how to configure each type of relationship: one-to-one, one-to-many, and many-to-many. EF Core’s By Convention relationship rules can configure many relationships quickly, but you’ll also learn about all the Data Annotations and Fluent API configuration options, which allow you to define precisely the way you want a relationship to behave. You’ll also look at features that allow you to enhance your relationships with extra keys and alternative table-mapping approaches. Finally, you’ll consider five ways to map your classes to the database.

8.1 Defining some relationship terms

 
 
 

8.2 What navigational properties do you need?

 
 
 
 

8.3 Configuring relationships

 
 
 

8.4 Configuring relationships By Convention

 
 
 

8.4.1 What makes a class an entity class?

 
 
 
 

8.4.2 An example of an entity class with navigational properties

 
 

8.4.3 How EF Core finds foreign keys By Convention

 
 

8.4.4 Nullability of foreign keys: Required or optional dependent relationships

 
 

8.4.5 Foreign keys: What happens if you leave them out?

 
 
 

8.4.6 When does By Convention configuration not work?

 
 

8.5 Configuring relationships by using Data Annotations

 
 

8.5.1 The ForeignKey Data Annotation

 
 
 
 

8.5.2 The InverseProperty Data Annotation

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest