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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:05:41+00:00 2026-05-30T11:05:41+00:00

just registered. First question :) If I have in my domain model entity Country

  • 0

just registered. First question 🙂
If I have in my domain model entity Country which have Name property and List of States property. Further that State have Name, List of Cantons property, further, Canton have municipalities, on the very end is city entity.

To exaplain better: I’m trying to seriliaze Country entity with CountryDTO and my contructor looks like this:

    public CountryDTO(Country x)
    {
        Name = x.Name;
        StateList = new List<StateDTO>();
        foreach (State state in x.States)
        {
            StateDTO stateDto = new StateDTO(state);
            StateList.Add(stateDto);
        }        
    }

But when I’m going deeper with StateDTO which looks like this>

    public StateDTO(State x)
    {
        Name = x.Name;
        CountryDTO Country = new CountryDTO(x.Country);

        CantonList = new List<CantonDTO>();
        foreach (Canton c in x.Cantons)
        {
            CantonDTO cantonDto = new CantonDTO(c);               
            CantonList.Add(cantonDto);
        }
    }

Since my StateDTO should be aware of his Country parent object I’m having this line
CountryDTO Country = new CountryDTO(x.Country); which is the problem, (possibly recursive reference), this will happen in Cantons with their State object as parent, and etc.
So how to load this parent entity and to avoid this error.
I need reference to parent object like Country.Name no CountryName as a string.

Hope, I was clear enough 🙂

  • 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-30T11:05:43+00:00Added an answer on May 30, 2026 at 11:05 am

    i think your problem is trying too much to mirror in the dto what you have the domain model. you would be better off considering what you really need on the client side and make the dto reflect that rather than being a duplication of what you have in the domain. this is especially true in that every time you are servicing a call to your service, you are serializing the entire hierarchy for everything in a country. seems like way too much to send back in almost all cases. here is a good post that describes this better:

    http://davybrion.com/blog/2012/02/dtos-should-transfer-data-not-entities/

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

Sidebar

Related Questions

Just a knowledge question which I would like to ask: For example, I have
I'm just making my first attempts with awk and have one, maybe, simple question.
This is my first time using stackoverflow for a question, I have read a
As described in another question , I have a set of Model objects and
I just have a question about my cuda program that I wrote. It allows
Just started learning x64 assembly and I have a question about functions, arguments, and
I've just registered my key to VS 2010 Professional, Mono for android has been
To me they seem to be the same thing, its just that registered processes
I have just finished creating an entire login and register systsem in PHP, but
Just checking my JS and I have an error, but I cannot see where.

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.