Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9279083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:32:33+00:00 2026-06-18T17:32:33+00:00

So have have an model object TreeNode : Public Class TreeNode{ Public int NodeId

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:32:35+00:00Added an answer on June 18, 2026 at 5:32 pm

    I found this partial solution. At first I though it was what I was looking for but after further inspection it only works if you start at the top of the tree. It doesn’t populate the Parent nodes if you start in the middle.

    How to assign parent reference to a property in a child with 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();
        foreach( var child in d.Children)
        {
           child.Parent = d;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model object called Country : class Country { public string Name
I have a simple model object: case class Region(id: String, revision: Option[String], name: String)
Given I have a Model object like ... public class MyModel { public int
I have a model object called Problem: [Table(Name = Problems)] public class Problem {
I have a parent-child view model object structure set up and need to update
Say I have a model object 'Person' defined, which has a field called 'Name'.
If I have Model.objects.all() I want to get only one object for any content_object=foo,
In Django, I have a model object in a list. [object, object, object] Each
I have a model object which is linked to a list of countries in
Hi I'm still new to java data management. I have a model object class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.