0
所以有具有模型对象TreeNode
:数据映射邻接表模型AutoMapper
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;}
}
该结构是通过使用一个Adjacency List Pattern数据库供电。我使用的WCF服务与AutoMapper填充我的模型类。
我想要做这样的事情:
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));
});
}
但很明显,这将导致一个无限循环(如果我只图孩子寿它的工作)。有什么方法可以使用AutoMapper填充我的树结构吗?
嘛。经过进一步检查,我意识到这种解决方案只适用于从树顶开始的工作。 – NSjonas 2013-02-08 19:33:07