I want to create a system of categories and sub categories for my website. Taking the StackOverflow tag system as an example, I want to represent a hierarchy like:
ProgrammingConcepts
Functions
FlowControl
Branching
Looping
Datastructures
List
Tree
Users should be able to search this tree, so a user could search for FlowControl
and get any articles tagged as FlowControl
, Branching
or Looping
.
How should I represent this in my database? The obvious solution is to have a table like this:
Categories
CategoryId int <PK>
ParentId int <Nullable>
CategoryName
I feel that this might be a hard to query on though. I'm just starting to learn asp.net mvc - in particular, the entity framework system seems to work much better than how I have previously worked with the database. Does this play nice with a tree structure?