开发者

Entity Framework Code First and relations

开发者 https://www.devze.com 2023-03-30 20:39 出处:网络
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.

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

精彩评论

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