How should I load tags like Stackoverflow does under each post?
I am building an ASP.NET MVC website where people can save their
bookmarks. Each bookmark belongs to one or more tags, and each tag can
have one or more bookmarks. I came up with these tables:
Users
Id
Username
Tags
Id
UserId
Title
Bookmarks
Id
UserId
Title
Link
Tags (separated by comma in one column just for presentation)
TagsBookmarks (junction table)
TagId
BookmarkId
An user can add 5 tags max for a bookmark. I want to show these tags under
each bookmark like stackoverflow does under each post. The problem is that
for each bookmark I need to execute a query (with NHibernate) to get its
tags. I solved this by adding a column inside the bookmarks table that
stores these tags comma separated. I only use this column for
presentation, not searching. So I can now load 20 bookmarks with their
tags with just one query. So not perfectly normalized but makes sense
right? Or is there a better way to do this?
No comments:
Post a Comment