0

How to map specific property to entity model and child property to another entity model?

My DTO is:

public class InsertApplicationDTO
{
    public ApplicationDetailsDTO ApplicationDetails { get; set; }
    public int AuthorityNum { get; set; }
    public string CertificateManager { get; set; }
    public int? Area { get; set; }
    public int? Team { get; set; }
}

I'd like to map the property ApplicationDetails to AppMirrorApplication

This is my profile:

    public NYProfile()
    {
        CreateMap<AppMirrorApplication, InsertApplicationDTO>().ReverseMap()
                .ForMember(x => x.ApplicationApproverTypeId, x => x.MapFrom(z => z.ApplicationDetails.ApplicationApproverTypeId))
                .ForMember(x => x.ApplicationCategoryId, x => x.MapFrom(z => z.ApplicationDetails.ApplicationCategoryId));
    }

This is working fine but i have a lot more property and i dont want to do it manually.

Also one of the Property in ApplicationDetailsDTO is object of type ClientDetailsDTO which i'd like to map it to AppMirrorClient

So the final result should be an entity called "AppMirrorApplication" which one of it property is type of AppMirrorClient.

Thank's

Steven
  • 166,672
  • 24
  • 332
  • 435
user384496
  • 180
  • 1
  • 2
  • 16

1 Answers1

0

Why do not just maps AppMirrorApplication twice from InsertApplicationDTO and from ApplicationDetails ? Like from this example:

AutoMapper convert from multiple sources

Oleg Bondarenko
  • 1,694
  • 1
  • 16
  • 19