Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoMapper MapFrom works for calculations?

Tags:

c#

automapper

I was told, that for 1 property<=>1 property mapping I should use MapFrom, but when the destination property is somehow calculated or modified, then I should use ResolveUsing. Still when I use this mapping it still works:

.ForMember(item => item.Validity, record => record.MapFrom(r => new DateInterval(r.Start, r.End)))

Actually I cannot even find any difference in the way the two functions work.

Is there any real difference?

like image 382
Kornél Regius Avatar asked Oct 21 '22 18:10

Kornél Regius


1 Answers

The MapFrom method will do things like null checks etc. that can be done be examining the expression tree. ResolveUsing - you don't really get anything "extra". The idea was MapFrom was from another property, and ResolveUsing, anything you want.

like image 78
Jimmy Bogard Avatar answered Nov 11 '22 15:11

Jimmy Bogard