0

Using the abp.io framework on their implementation of AutoMapper which is integrated with the framework I'm having some issues mapping collections.

With abp.io our entities have various audited properties, creation, mofification times and records etc. These properties do not show on our Dtos. The mapping config extension IgnoreFullAuditedObjectProperties() should stop these properties being erased when updating an entity using AutoMapper.

However I'm having some issues with CreationTime and and CreatorId being cleared on update when mapping a collection specifically.

I have the following mapping:

CreateMap<ExpenseDto, Expense>()
        .IgnoreFullAuditedObjectProperties()
        .ReverseMap();

If I update objects using the mapper individually IgnoreFullAuditedObjectProperties is followed, and I keep the CreationTime and CreatorId.

Like this:

ObjectMapper.Map<ExpenseDto, Expense>(expenseDto, expense);

That works as expected.

However if I try and update a collection using the mapper, I loose all the CreationTime and CreatorId properties.

ObjectMapper.Map<List<ExpenseDto>, List<Expense>>(expenseDtos, expenses);

Everything else maps ok with the updated collection mapping, it just seems to not use the IgnoreFullAuditedObjectProperties() config on the mapping.

Am I doing anything wrong?

user1259167
  • 447
  • 5
  • 15
  • Hi, Firstly ABP as the best practice doesn't suggest mapping entity to DTO. Just suggest mapping DTO to the entity. Secondly,after using *IgnoreFullAuditedObjectProperties* it should ignore the related properties. Check https://docs.abp.io/en/abp/latest/Entities#base-classes-interfaces-for-audit-properties please – malik masis Apr 19 '22 at 08:32
  • @malikmasis But what I'm saying is IgnoreFullAuditedObjectProperties works when mapping a single item but not when mapping a collection. Where as everything else works fine when mapping a collection so that should be supported with automapper. I'm having to run a foreach mapping each item individually. Also I am mapping DTO to entity here? not sure how the first comment applies here? – user1259167 May 11 '22 at 22:17

0 Answers0