as I am currently learning how Entity Framework works I got following question:
On creating a basic 1:n relationship (code-first) I did read that I should do it like this:
public class Post
{
public int PostId { get; set; }
[MaxLength(200)]
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
There are both reference and Id field for the book-post relationship. Is this required?
I always did the database connection manually and only had the reference field
public Blog Blog { get; set; }
This way I can access the Blog Id too and I don't have to keep both up-to-date. It seems like the EF migrations don't work this way.
Any reasons for that? Is it best-practice to keep both, reference and Id field?