More in this section

Forums / Developing with Sitefinity / Create a HierarchicalTaxon Parent Ref

Create a HierarchicalTaxon Parent Ref

1 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Aug 2012
    Link to this post
    ### EDIT ###
    Got it, for anyone else, make sure to set the Taxonomy property of your new category to be the category.
    (this one)
    this.PageTaxonomyManager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);



    If I create a new HierarchicalTaxon object, how do I go about setting its parent?

    I'm trying something like this, but I get object ref error on SaveChanges

    foreach (var c in children)
                {
                    //c.ItemParent = parentCategory;
                    //c.Parent = parentCategory;
                               parentCategory.Subtaxa.Add(c);
     
                    //this.Category.Taxa.Add(c);
                    this.PageTaxonomyManager.SaveChanges();
               }
    (various combos)

    Server Error in '/' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 58:                 c.Parent = parentCategory;
    Line 59:                 this.Category.Taxa.Add(c);
    Line 60:                 this.PageTaxonomyManager.SaveChanges();

1 posts, 0 answered