This is more or less a best-practice question:
I’m working on a site that requires me to relate some tables to several different tables.
For instance, I have a Comments-table, that I would like to relate in a way such as one might comment on entities in Table A, but also in Table B separately.
Similarly, I have a rating-table that I would like to do the same with, so that one could rate different aspects in the site.
I’ve touched upon one method that implies having a loose relation with a Relationships-table with a PrimaryKey(Guid) and ForeignKey(Guid), and then using Guids as Primary key in both the Comments-table and the Rating-table – However this implies I’m gonna need Guid as primary key in the other tables as well.
Anyone have any great ideas here? Greatly appreciated 🙂
PS. If it’s interesting, I’m creating an ASP.NET MVC2 app with an ORM (either EF, Linq2Sql or NHibernate.. doesn’t really matter :))
You could use a single comments/ratings table, but use a separate table for each related entity to maintian the comment to entity relationship. If you had Posts and Pages, each with comments, it would look something like this: