Entity Framework Code First and relations
I have a Post class for a website representing posts made on the website.
Each post is part of a category, and I have a corresponding Category class.
How would I relate posts to catego开发者_如何学Cries? By letting the post have an int CategoryId
or a Category Category
?
I do both. This allows full navigation of the caterogy from post, but also gives you the foreign key if that is all you need.
public int CategoryID { get; set; }
public virtual Catergory Category { get; set; }
精彩评论