Let's take a look at the example from the official docs:
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; }
}
As we can see, we have fully defined one-to-one relationship between Blog and BlogImage, where Blog is parent, and BlogImage is child entity.
But, if we'll take a look at created tables, we'll see this headers:
- BlogId, Url for Blog
- BlogImageId, Image, Caption, BlogId for BlogImage
I have some misunderstood with this BlogId in BlogImage table, shouldn't we have defined the BlogImageId foreign key in Blog table, what's the reason, to define foreign keys in child entiities nor in parent's? If we have thousand parent's of one child, there would be thousand of foreign keys in child entity! Very strange.