Hi there,
I’m trying to map between a list of composed Dbo’s to a list of Dto’s using AutoMapping.
Consider the flowing code:
public class Car
{
public string Model {get; set;}
public int Year {get; set;}
public int MaxSpeed {get; set;}
}
public class TechRevision
{
public bool Ok {get; set;}
public string RevisionDate {get; set;}
}
public class CarRevisionDbo
{
public Car Car {get; set;}
public List<TechRevision> TechRevisions {get; set;}
}
public class CarRevisionDto
{
public string Model {get; set;}
public int Year {get; set;}
public int MaxSpeed {get; set;}
public List<TechRevision> TechRevisions {get; set;}
}
i would like to map between a list of CarRevisionDbo to a list of CarRevisionDto, where Car
is also destructed (maped) into CarRevisionDto
.
You can see the code here: https://gistlyn.com/?gist=52c37e37b51a0ec92810477be34695ae.
I expect the following result: [{“Year”:2000,“MaxSpeed”:190,“Model”:“BMW”,“TechRevisions”:[{“Ok”:true,“RevisionDate”:“2004”},{“Ok”:true,“RevisionDate”:“2008”}]},{“Year”:“2002”,“MaxSpeed”:190,“Model”:“VW”,“TechRevisions”:[{“Ok”:true,“RevisionDate”:“2006”},{“Ok”:true,“RevisionDate”:“2010”}]}]
Is there any way to do this using AutoMapping?
This result is easily achieved using Automapper library ( https://automapper.org/ ). Why ServiceStack does not use this library?
Cheers,
WLab