How can I map a c# class called Unit which has again a List<Unit>
.
The concrete scenario is a rootUnit object which contains a List which are the first level children.
The first level children unit objects will not contain any other units so there will be no recursion in the hierarchy.
public class Unit
{
public Unit()
{
// Explicitly set the default value for the first unit in a hierarchy
HierarchyIndex = 0;
Units = new List<Unit>();
}
public List<Unit> Units { get; set; }
public int UnitId { get; set; }
public string Name { get; set; }
public Nullable<int> ParentId { get; set; }
public int TemplateId { get; set; }
public bool HasChildren { get; set; }
public bool IsFolder { get; set; }
public DateTime CreatedAt { get; set; }
public int HierarchyIndex { get; set; }
}
Map the unit above to this viewmodel:
public class UnitTreeViewModel
{
[JsonProperty("key")]
public int UnitId { get; set; }
[JsonProperty("title")]
public string Name { get; set; }
[JsonProperty("isLazy")]
public bool HasChildren { get; set; }
[JsonProperty("isFolder")]
public bool IsFolder { get; set; }
}