EF Core Has/With Pattern For Configuring Relationships

When configuring relationships with the Fluent API, you will use the Has/With pattern. The Has side of the pattern is represented by the HasOne and HasMany methods. The With side of the relationship is represented by the WithOne and WithMany methods.

The HasOne method is used for reference navigation properties as is the WithOne method. The HasMany and WithMany methods are used for collection navigation properties.

A Has* method must be combined with a With* method to configure a valid relationship.


Date Modified: 2023-02-27
Author:

Edit this page in GitHub

Got any EF Core Question?