These are my classes:
public class EventLog {
public string SystemId { get; set; }
public string UserId { get; set; }
public List<Event> Events { get; set; }
}
public class Event {
public string EventId { get; set; }
public string Message { get; set; }
}
public class EventDTO {
public string SystemId { get; set; }
public string UserId { get; set; }
public string EventId { get; set; }
public string Message { get; set; }
}
Basically I need to go from a single object, with a nested list, to a list of objects with values from the nested list and the parent object. Can this be done in AutoMapper? I realize that I can easily map the Events list and get a list of EventDTO objects and then manually set the SystemId and UserId, it would just be very convenient to let AutoMapper handle it for me.
You will need these three mapings with one custom converter:
Thus you configured mappings from
Event
toEventDTO
and fromEventLog
toEventDTO
you can use both of them in custom converter:Sample code with NBuilder: