如何将多个评论链接到数据库中的请求?
因此,我正在 ASP.net、C#、SQL Server 中开发这个请求管理系统 Web 应用程序,并且目前正在设计数据库。我的问题是,我想要一个请求来获得来自不同用户的多个评论。我有一个请求表和一个用户表。如何将多个用户的多个评论链接到一个请求?
我应该为评论创建一个单独的表吗?那什么...
谢谢!
So I am developing this request management system web app in ASP.net, C#, SQL server and am currently designing the database. My question is that, I want a request to have multiple comments from different users. I have a Requests table and a Users table. How can I link multiple comments from multiple users to a request?
Should I create a separate table for Comments? then what...
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用联结来建模多对多关系表,例如
Comments
,其中关系的每个元组都有一个Requests
表主键的外键,以及一个Users
表的外键表主键。You can model a many-to-many relationship with a junction table, e.g.
Comments
, where each tuple of the relation has a foriegn key to theRequests
table primary key, and a foriegn key to theUsers
table primary key.我建议使用一个单独的评论表,其中包含请求和用户的键。您必须以某种形式实现这一点,因此将其作为显式注释表是有意义的。
这是标准的多对多关系,正如 devdigital 指出的那样,您通常会使用连接表对此进行建模。有时这只是一个链接表,但在这种情况下,您可以显式地将其设为注释表。
在您的编码中,您可以创建具有评论列表的用户对象,并使用评论列表进行请求。评论可以引用用户和请求,但不要直接加载它们,因为您将产生循环引用!
I would suggest a separate comments table, with keys of request and user. You will have to implement this in some form, so doing it as an explicit comments table makes sense.
This is a standard many-to-many relationships, and, as devdigital points out, you would normally model this with a junction table. Sometimes this is simply a linking table, but in this case, you can make it a comments table explicitly.
In your coding, you can then create objects of user with a list of comments, and request with a list of comments. And the comments can have a reference to the users and requests, but don't load these in directly, as you will have circular references!