0

I have model:

 public class Category
 {
    [Key]
    public int CategoryId { get; set; }
    public string Name { get; set; }
    public int Parent { get; set; }
  }

I want to create a database using code first and how I add foreign key for Parent? (Create relation Parent->CategoryId)

Nilks
  • 446
  • 4
  • 14
qqla333
  • 47
  • 1
  • 6
  • 1
    Try [Self referencing / parent-child relationship in Entity Framework](http://stackoverflow.com/questions/9955491/self-referencing-parent-child-relationship-in-entity-framework) – tchelidze Jan 10 '16 at 19:42

1 Answers1

2
    public class Category

 {
    [Key]
    public int CategoryId { get; set; }
    public string Name { get; set; }
    public int? ParentID { get; set; }
    [ForeignKey("ParentID")]
    public virtual List<Category> Subcategories { get; set; }
  }
Majed
  • 53
  • 8