score:4

Accepted answer

Replace

GetRootCat(cat); 

with

return GetRootCat(cat);

score:2

It doesn't "fail to return", it returns to itself because it's a recursive call. But when it calls itself, it throws away the return value, and falls through to the return cat, which gives you the parent of the category you called it with.

This would be more sane:

private Category GetRootCat(Category cat) {
    if (cat.PCATID == null) { /* This is the root */
      return cat;
    } else {
        Category parent = repository.Categories.FirstOrDefault(x => x.CategoryID == cat.PCATID);
        return GetRootCat(parent);
    }
}

Related Query

More Query from same tag