I have a problem mapping one of my DTOs which have a collection, to the flattened version in the entity model.
Here's the DTO classes:
public class Location {
public int LocationId {get; set;}
public string LocationName {get;set;}
public List<HoursOfOperation> HoursOfOperation {get; set;}
}
public class HoursOfOperation {
public int WeekNumber {get; set;}
public int DayNumber {get; set;}
public List<TimeSlot> OperatingHours {get; set;}
}
public class TimeSlot{
public TimeSpan StartTime {get; set;}
public TimeSpan EndTime { get; set;}
}
Here's my entity model class:
public partial class HoursOfOperation
{
public int HoursOfOperationId { get; set; }
public int FkLocationId { get; set; }
public short WeekNumber { get; set; }
public short DayNumber { get; set; }
public TimeSpan StartTime { get; set; }
public TimeSpan EndTime { get; set; }
}
I've used Automapper and got this far:
public OpHoursMappingProfile()
{
CreateMap<HoursOfOperation, Models.ClientDb.HoursOfOperation>()
.ForMember(dest => Enum.GetName(typeof(DayOfWeek), dest.DayNumber), opt => opt.MapFrom(t => t.DayNumber))
.ForMember(dest => dest.WeekNumber, opt => opt.MapFrom(t => t.WeekNumber));
}
I'm not sure how to map the timeslots. I tried creating a custom extension as explained here, but it didn't help.