I have been tasked with looking after a web app that was built using automapper to complete all data transformations. So far, I have managed to get most issues sorted out, but I have one that is turely perplexing, at the moment.
In the database, I have a field called HasDocuments which is defined as a bigInt.
This field holds hierarchy data, but for this viewModel, it is used as a flag just to show if a value is present.
So my viewModel has a proptery defined as a nullable bool.
public bool? HasDocuments { get; set; }
All good so far.
When the call to the database is made
I have checked all of the mapper cfg to check and none of them are called and come across some great articles on SO like:
AutoMapper ProjectTo() configuration question
From articles I know that the ProjectTo command is different to the MapFrom command.
I am just not getting what is going on here.
Can anyone please help?
UPDATE
As per request the following is the mapping config.
CreateMap<Parcel, BaseParcelDataContract>()
.BeforeMap((s, d) => { System.Diagnostics.Debug.Print("");})
.Include<Parcel, ParcelDataContract>();
Parcel is the base DB object and has HasDocuments property as nullable long, BaseParcelDataContract is passed back to the Controller and has the HasDocuments property as a nullable bool.
I would like to thank Luican for his answer. In the end, I used a straight left => right swap. But yes Luican. Automapper cannot do this. Unless anyone can show me.
Award to Luican.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.