How to map recursive relation on self in Entity Framework code-first approach

后端 未结 2 1916
刺人心
刺人心 2020-12-14 04:47

All I want to create is basic recursive category. Category is root if RootCategory_Id is set to null and it belongs to some other category if it is set to some

2条回答
  •  暖寄归人
    2020-12-14 05:27

    is lazy loading on or off?,

    You may need to include the child relationship in the query like so

    _db.Categories.Include("ChildCategories").FirstOrDefault(x => x.ID == 4) 
    

提交回复
热议问题