Reputation: 10482
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 categories? By letting the post have an int CategoryId
or a Category Category
?
Upvotes: 0
Views: 113
Reputation: 771
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; }
Upvotes: 3