I am Changing the AutoMapper to Mapster and i am new to mapster.
I have two classes like below
public class PayrollLineItems
{
public int PayrollLineItemID{get;set;}
public datetime PlannedStartDate {get;set;}
public datetime PlannedEndDate {get;set;}
public datetime ActualStartDate {get;set;}
public datetime ActualEndDate {get;set;}
}
public class PayableLineItems
{
public int PayrollLineItemID {get;set;}
public TimePeriod PlannedTimePeriod {get;set;}
public TimePeriod ActualTimePeriod {get;set;}
}
public class TimePeriod
{
private DateTime _Start;
private DateTime _End;
private TimeSpan _ActualDuration;
public TimePeriod(DateTime start, DateTime end)
{
this._Start = start;
this._End = end;
this._ActualDuration = (this._End-this._Start);
}
}
Below is the AutoMapper code to map the PlannedTimePeriod property of PayrollLineItems and PayableLineItems.
CreateMap<PayrollLineitems, PayableLineItems>()
.ForMember(x => x.PlannedTimePeriod,
option => option.MapFrom<TimePeriod>(
(src, dest) => new TimePeriod(src.PlannedStartTime.HasValue ? src.PlannedStartTime.Value : DateTime.MinValue,
src.PlannedEndTime.HasValue ? src.PlannedEndTime.Value : DateTime.MinValue))
)
I am using the below code in Mapster to map the PlannedTimePeriod property
config
.NewConfig<PayrollLineitems, PayableLineItems>()
.Map(x => x.PlannedTimePeriod, dest => new TimePeriod(dest.PlannedStartTime.HasValue ? dest.PlannedStartTime.Value : DateTime.MinValue,
dest.PlannedEndTime.HasValue ? dest.PlannedEndTime.Value : DateTime.MinValue))
I am getting the "No default constructor for type 'TimePeriod', please use 'ConstructUsing' or 'MapWith'" error with MapSter.
Can anyone please help me with the above issue.
Thanks in advance for helping.