So have have an model object TreeNode
:
Public Class TreeNode{
Public int NodeId {get;set;}
Public String Name {get;set;}
Public int ParentId {get;set;}
Public TreeNode Parent {get;set;}
Public List<TreeNode> Children {get;set;}
}
This structure is powered by a databases using an Adjacency List Pattern. I'm using a WCF service with AutoMapper to populate my Model classes.
I want to do something like this:
public static void ConfigureMappings()
{
Mapper.CreateMap<TreeNodeDto, Taxonomy>()
.AfterMap((s, d) =>
{
//WCF service calls to get parent and children
d.Children = Mapper.Map<TreeNodeDto[], TreeNode[]>(client.GetTreeChildren(s)).ToList();
d.Parent = Mapper.Map<TreeNodeDto, TreeNode>(client.GetTreeParent(s));
});
}
But obviously this causes an infinite loop (it does work if I only map children tho). Is there any way to populate my tree structure using AutoMapper?