5

I have two lists, SRCList and DESTList.

SRCList object has got 6 records.

I am using automapper to map these two list.

While mapping, automapper encounters any problem in mapping the 4th record out of 6, I get AutoMapperMappingException.

Can I skip mapping of the record which caused error and continue mapping others? So, in the above example, DESTList will have 5 records, skipping the 4th one.

MARKAND Bhatt
  • 2,428
  • 10
  • 47
  • 80
  • 1
    Yeah. I tried. I get AutoMapperMappingException – MARKAND Bhatt Jan 16 '18 at 22:46
  • 1
    It's important to understand why Automapper is throwing an exception for one item. I can't recommend writing something that works 5/6 of the time and not knowing why the other 1/6 doesn't. What is the exception? It's going to contain specific information about why it can't map that. With that you'll almost certainly be able to add some missing detail to your mapping and then it will work. – Scott Hannen Jan 17 '18 at 02:23
  • Automapper cant map because of conversion. I am trying to convert one source field from string to int. And the exception occurs when there source field is empty. This is one scenario. There could be many more where we don't have any control on the source data. – MARKAND Bhatt Jan 17 '18 at 03:07
  • You should avoid the exceptions in the first place. – Lucian Bargaoanu Jan 17 '18 at 05:03

0 Answers0