Fully-defined relationships - under the hood

The EF Core uses the mechanism internally for creating relationship between entities based on the following scenarios:

  • If the two entities have navigation properties pointing to each other; EF will configure them as inverse navigation properties

In the following code, the Posts property of the Blog entity and the Blog property of the Post entity would be configured as inverse navigation properties:

public class Blog{    // Code removed for brevity    public ICollection<Post> Posts { get; set; }    }public class Post{    // Code removed for brevity    public Blog Blog { get; set; }}

The following image illustrates the relationship created based on the navigational properties:

  • EF will consider the property ...

Get Mastering Entity Framework Core 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.