All root categories in table have a PCATID of null.
The method actually does the job, sets cat to the very root
category, but then amazingly fails to return it once
it hits return cat; does some weird jumping in and
out of the “if” statement, then again to GetRootCat(cat);
and returns not the root category, but the first parent
category of cat.
Call:
listModel.PCATID = GetRootCat(cat).CategoryID;
Method:
private Category GetRootCat(Category cat)
{
if (cat.PCATID != null)
{
cat = repository.Categories.FirstOrDefault(x => x.CategoryID == cat.PCATID);
GetRootCat(cat);
}
return cat;
}
Replace
with