Nhibernate,需要帮助构建实体类
我有3张桌子,它们很简单。用户、帖子、收藏。
User Table:
Id: int
Name: string
--------------------------------
Post Table:
Id: int
Title: string
UserId: int (this is the FK)
--------------------------------
Favorite Table:
UserId: int
PostId: int
--------------------------------
我为 User 和 Post 表创建 2 个类文件。不知道如何在那里添加收藏夹表,收藏夹表允许用户为他们最喜欢的帖子添加书签。
public class User : Entity
{
public User() { this.Posts = new List<Post>;}
public virtual string Name { get; set; }
public virtual IList<Post> Posts {get; set;}
}
public class Post : Entity
{
public Post() {}
public virtual string Title { get; set; }
public virtual User User { get; set; }
}
I have 3 tables, they are very simple. User, Post, Favorite.
User Table:
Id: int
Name: string
--------------------------------
Post Table:
Id: int
Title: string
UserId: int (this is the FK)
--------------------------------
Favorite Table:
UserId: int
PostId: int
--------------------------------
I create 2 class files for User and Post tables. Dont know how to add Favorite table there, Favorite table allows User to bookmark their favorite posts.
public class User : Entity
{
public User() { this.Posts = new List<Post>;}
public virtual string Name { get; set; }
public virtual IList<Post> Posts {get; set;}
}
public class Post : Entity
{
public Post() {}
public virtual string Title { get; set; }
public virtual User User { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你们有多对多的关系。最喜欢的表是用户和帖子之间的关系表。
You have a many to many relation. The Favorite Table is the relation table between User and Post.
菜鸟,谢谢你的帮助。
添加您的表格后,我添加了
公共虚拟 IList 收藏夹 { get;放;}
用户表和帖子表。看起来还是不太对劲。
Rookian, thanks for you help.
After Add your table in, I added
public virtual IList Favorites { get; set;}
to both User and Post Tables. Still doesn't seem quite right.