2

I have a entity class that is populated from the backend and then automapper is used to map the data to a new DTO Model. I have other data coming in from another source that has some same data and new data that i want placed into the DTO. When i say same data, I mean, some properties of the new source should overwrite properties in the dto that already have data in them.

Is there a way to use automapper or some nice easy way to merge this data? or is the only way to do this by manual mapping?

Thanks

user1161137
  • 1,067
  • 1
  • 11
  • 31
  • 1
    I think its not good approach. You should create new DTO everytime when you need modify data. IMHO Composing DTO during life time its bad. – daremachine Oct 13 '17 at 14:45
  • i need to combine the values because a processor that is finally called takes a single model that needs data from multiple sources overwritten in a particular order. – user1161137 Oct 13 '17 at 14:55
  • Possible duplicate of [Automapper: Update property values without creating a new object](https://stackoverflow.com/questions/2374689/automapper-update-property-values-without-creating-a-new-object) – Progman Oct 13 '17 at 17:29
  • @Progman tx. i think you are right. will try that out. – user1161137 Oct 13 '17 at 18:02

1 Answers1

1

You can try something like this:

var model = Mapper.Map<Model>(dto1);
Mapper.Map(dto2, model);
Valerii
  • 2,147
  • 2
  • 13
  • 27