Recently I was working on a project that required a categorization option. I wanted the user to have the option to create categories and as many subcategories as they wanted. To realize this I created a category model that was self referencing:
1 2 3 4 5 6 7 8 9 |
public class Category { public int Id { get; set; } public string Name { get; set; } public int? ParentId { get; set; } [ForeignKey("ParentId")] public virtual Category Parent { get; set; } } |