-
Notifications
You must be signed in to change notification settings - Fork 42
Nested DTOs
There are a few times when you might have nested DTOs. This can happen when you have relationships. A good example of this is CrudCustomerAddressDto.cs, which includes a CrudAddressDto.cs.
This will work, but you have to make sure that when you use the top level DTO, in this case CrudCustomerAddressDto
, that the mapping for the related DTO, in this case CrudAddressDto
is setup, otherwise you will get an exception from AutoMapper.
In the CrudCustomerAddressDto.cs code you will see the property below, which tells GenericServices to set up the CrudAddressDto
mapping before it is called:
protected override Type AssociatedDtoMapping
{
get { return typeof(CrudAddressDto); }
}
If you have more than one associated DTO you need to override the AssociatedDtoMappings
(plural) property. There is an example of this in the TabNeededTagAndDelegatePostDto
class in the GenericServices Unit Tests.
If you are updating a data item that has linked relationships the DTO copying will work, but you need to make sure all the related classes are loaded for the update to them to work. See the overriding of FindItemTrackedForUpdate
in CrudCustomerAddressDto.cs for an example of this.
Live example web sites!
Introduction/Overview
Commands and options
- Introduction to Commands
- Key interfaces
- Calculated properties
- DoNotCopyBackToDatabase attribute
- Configuration Options
Data Transfer Objects (DTOs)