Search code examples
c#pocodto

Should DTOs contain other DTOs or does this constitute 'behaviour'?


We are starting on a new project and are designing the DTOs that will get injected into the corresponding POCOs with the behaviour. However every example of a DTO I can find only contains value types such as:

public class CustomerDTO
{
  public int Age { get; set; }
}

But what we would like to do is add DTO properties that reference collections of other DTOs such as:

public class CustomerDTO
{
  public List<AddressDTO> Addresses { get; set; }
}

Is this a bad design idea that will give us problems down the line? Or, is there no other way of designing real DTOs that don't reference each other?


Solution

  • It is typical navigation properties that you want to add to your DTO. I think it is valid to use them and the only problem that you can meet is circular references in serialization and so on.