I have the folowing class and its dto:
public class Node
{
public int NodeId { get; set; }
public virtual ICollection<Node> ChildrenNode { get; set; }
public virtual Node ParentNode { get; set; }
}
public class NodeDto
{
public int NodeId { get; set; }
public ICollection<NodeDto> ChildrenNode { get; set; }
public NodeDto ParentNode { get; set; }
}
And my mapper is just simple:
Mapper.CreateMap<Node, NodeDto>();
When I call ProjectTo from an IQueryable, I get a StackOverflowException. I already tried Mapper.CreateMap<Node, NodeDto>().MaxDepth(3)
and Mapper.CreateMap<Node, NodeDto>().PreserveReferences()
and none of these worked.
What can I do to mantain self reference?
If it'll be of any help, I need to access ParentNode and ChildrenNode from any depht, but inside a ParentNode I don't need a ChildrenNode. Something like this: node.ParentNode
and node.ChildrenNode[0].ChildrenNode
, but no need for node.ParentNode.ChildrenNode
;