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 5970295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:21:16+00:00 2026-05-22T20:21:16+00:00

I have the following entity classes, which are mapped from virtually identical view model

  • 0

I have the following entity classes, which are mapped from virtually identical view model classes:

public class Node
{
    public IList<Node> Children { get; set; }
    public Node Parent { get; set; }
    public string Text { get; set; }
}

public class Tree
{
    public Node Root { get; set; }
}

Using the following view model structure

Tree 
    -> Root
        -> Children { node1, node2 }

Once the view model is mapped to the entity, the first child node, of the root node, is the root node and, as a result, I’m getting an infinite loop when I traverse the entity object structure.

Anybody have an idea why this is happening and how to resolve it?

Many thanks

Steve

  • 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-05-22T20:21:17+00:00Added an answer on May 22, 2026 at 8:21 pm
    Mapper.CreateMap<NodeViewModel, Node>()
        .ForMember(dto => dto.Children, 
                   opt => opt.MapFrom(src => src.Children.Select(nodevm => Mapper.Map<NodeViewModel, Node>(nodevm)).ToList()))
        .ForMember(dto => dto.Parent,
                   opt => opt.MapFrom(src => Mapper.Map<NodeViewModel, Node>(src.Parent)))
        .ForMember(dto => dto.Text,
                   opt => opt.MapFrom(src => src.Text));
    

    Something like that schould work as the AutoMapper Configuration.

    PS: I did not try it by now, but as I use the AutoMapper very often I think it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entity structure: public class Party { public Int32 PartyId {
I have an Entity baseclass which the classes Player and Enemy Inherit. class Entity
I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue
I have a problem with the following Linq query using Entity Framework: from o
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following kinds of classes for hibernate entity hierarchy. I am trying to
I have the following JPA entity classes (example case). A House belongs on a
I have a POJO class, say Foo, which has a Set of other entity
Say I have two classes: class A(db.Model): class B(db.Model): a_reference = ReferenceProperty(A) I can
I have the following scenario (in Java / Hibernate): I have two entity classes:

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.