Building a tag/category system [closed]
I am trying to create a dynamic website that needs a category system - sort of like what there is on this site.
I need entries to the database to be able to have categories that they are under so that if someone selects a category, I can easily find all entries under that category... Nothing more advanced than that.
So far, the way I have thought about it is to add the following to the individual en开发者_StackOverflow中文版tries:
public List<Category> Categories { get; set; }
And then for Category, I have:
public class Category
{
public int ID { get; set; }
public string Name { get; set; }
}
I still need to work out a way to have a select box and save the list/create new categories, but, I don't imagine this being that hard. I tried looking at the EF generated data from this, and, it looked a little bit mucky which got me concerned. I am just very hesitant before going any further as this seemed too easy and I am sure I have overlooked something....
...I just don't know if I am on the right track at all and was wondering if someone who has done this before can give any advice?
Assume I've got Questions and Tags they might look like this:
Questions
---------
Id
Title
Text
Tags
---------
Id
Name
Then a table to map questions to tags
QuestionTags
------------
QuestionId
TagId
Where QuestionId and TagId are foreign keys to the Id columns of Questions and Tags, respectively. And they are, necessarily, the primary key for the QuestionTags table (since you don't tag a question with the same tag multiple times).
That might be how I'd lay out the tables, though there are other approaches.
加载中,请稍侯......
精彩评论