Building hierarchy of Departments

Topics: Customizing Orchard, Writing modules
Jul 11, 2011 at 3:13 PM
Edited Jul 11, 2011 at 3:15 PM

Hi all,

I have the following question: lets say I have a Department part with underlying Department part record. My aim is to build a hierarchy of departments - that is any entity should have a reference to its parent (if parent is NULL, Department is root).
So I am going to solve this in the following way:

SchemaBuilder.CreateTable("DepartmentPartRecord", x =>
x.ContentPartRecord()
.Column<string>("Name")
.Column<DateTime>("DateCreated")
.Column<DateTime>("DateDeleted")
.Column<int>("Department_id"));

here is a record definition:

public class DepartmentPartRecord : ContentPartRecord
{
    public virtual string Name { get; set; }
    
    public virtual DateTime DateCreated { get; set; }

    public virtual DateTime? DateDeleted { get; set; }

    public virtual DepartmentPartRecord Department { get; set; }
}

so here is a self-reference. When developing Create functionality within my Department controller and following the common schema:

var department = orchardServices.ContentManager.New<DepartmentPart>("Department");
orchardServices.ContentManager.Create(department);
var model = orchardServices.ContentManager.UpdateEditor(department, this);
I get the 'StackOverflowException'. I'm not aware of internal Orchard mechanisms, and cannot get why Orchard is trying (this is my guess) to update 'parent' Department reference, while it is NULL?
Please could someone advice on this issue?

Thanks,
Paul Borovik

Coordinator
Jul 11, 2011 at 7:56 PM

You may need to use some lazy fields in there, but this should in principle work. Can you attach a debugger and determine where the SO is happening?

Jul 12, 2011 at 10:41 AM
Edited Jul 12, 2011 at 10:50 AM

Oh, sorry, the reason seems to be here:

public new bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class
{
    return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

instead of

bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties)
{
    return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}
Not surprising I've got a SO, thank you for help.