If we have more than one navigation property in an entity, it makes sense to use an inverse property to pair the navigational properties for a relationship. There will be occurrences where even though we have a fully-defined relationship, we still need an inverse property in order to pair up the navigational properties due to custom naming conventions that don't fall into any of EF's discovery mechanisms:
In the following code, the custom foreign key and navigation property were configured in the inverse navigation property:
public class Blog
{
... // code removed for brevity
[InverseProperty("SomeBlog")]
public ICollection<Post> SomePosts { get; set; }
}
public class Post
{
... // code removed for brevity
public int SomeBlogId { get; set; }
public Blog SomeBlog { get; set; }
}
The following image illustrates that the custom foreign key and navigation property were configured in the inverse navigation property:
We have introduced the SomeBlog inverse property in the Blog entity, which pairs with the SomeBlog navigation property of the Post entity.