I have an ASP.NET MVC application with a Microsoft SQL Server database accessed through Entity Framework. I want to implement a tag/hashtag/keyword feature. I have multiple types of objects in the application, but all of them will have tags and one will be able to search and find them using these tags.
I am confused about how to implement this feature.
Here are some ways I thought about: 1. Currently, the IDs for each object are ints that range from 0 to n. This is a problem because ID 1156 could refer to multiple objects: Row 1156 in Table1, Row 1156 in Table2. Should I change the implementation of the IDs to string GUIDs?
Should I create a table for the tags and a separate table to relate the keywords to the objects? (TagGuid, ObjectGuid). This implementation would necessitate another query to find the objects.
Should I just create a column in each table named Tags and list the tabs as strings? "tag1 tag2 tag3"? How would this impact performance as far as the duration of a search query goes? What if need to count the objects residing under a certain tag?
Looking for other possible solutions as well. Apologies for the vagueness, I don't know where to start - I could just go for either implementation but I think there's maybe a consacrated way of doing this task.
Create a separate table for your Hash-tags and have multiple foreign keys to your other tables.
So imagine this...
Table > Hashtag
Col > HashtagId
Col > Tag
Col > ThreadId
Col > CommentId
etc...
If you make your Foreign keys optional, when using EF to query your data source you can filter your results using.
var commentHashtags = DbSource.Hashtags.Where(tag => tag.CommentId != (int?)null);
Wherever the CommentId isn't null, the other columns will be, unless of course you fill more than one of the Foreign Key columns in a single row.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments