The above answer is absolutely correct.
For reader information only: This is well explained in the official documentation.
one to one
One-to-one relationships have link navigation properties on both sides. They follow the same conventions as a one-to-many relationship, but a unique index is entered for the foreign key property to ensure that only one dependent applies to each principal.
public class Blog { public int BlogId { get; set; } public string Url { get; set; } public BlogImage BlogImage { get; set; } } public class BlogImage { public int BlogImageId { get; set; } public byte[] Image { get; set; } public string Caption { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } }
Note
EF will choose one of the entities that will be dependent, based on its ability to detect a foreign key property. If the wrong object is selected as dependent, you can use the Fluent API to fix this.
immirza
source share