It loads category but always with null parent. I want get hierarchy category with given ID.
public static Category GetCategory(System.Guid ID, ActionLinkInfo AInfo)
{
Category category = null;
using (TIKSN.STOZE.Data.StozeContext DContext = new Data.StozeContext())
{
var cats = from cat in DContext.Categories where cat.ID == ID select cat;
foreach (Data.Category Cat in cats)
{
category = new Category(Cat, Cat.Parent == null ? null : GetCategory(Cat.Parent.ID, AInfo), AInfo);
}
}
return category;
}
Try this:
Or you can change your model, to include that
ParentIDas an integer inCategoryclass:With that you’ll be able to get
Cat.ParentIDwithout loading wholeParentobject from database.