我有一个模型,它是我的基础模型,其中包含许多字段。然后我有 4 个 DTO,它们是该模型的一部分。我想最终将它们全部映射到模型,但每次映射它都会覆盖以前的映射。
例如
_model = new GenericModel();
_model.ExampleNotInDTO = "This Gets Overwritten being set previously";
//First Mapping below overwrites the property I set above and
// sets only the fields in the business dto.
Mapper.CreateMap<BusinessDto, GenericModel>();
_model = Mapper.Map<BusinessDto, GenericModel>(searchResultsQuery.BusinessDto);
//Now doing another mapping just below it nulls out all the previous
// stuff and only fills in the events dto.
Mapper.CreateMap<EventsDto, GenericModel>();
_model = Mapper.Map<EventsDto, GenericModel>(searchResultsQuery.EventsDto);
将我的所有 4 个 dto(例如上面只有 2 个)放入同一个 _model 对象的最佳方法是什么?