开发者

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; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜