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.
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?
The gistlyn link doesn’t contain your example, did you forget to save it? Feel free to paste the entire runnable source code here as well. When pasting source code paste them within code blocks so it’s properly escaped/formatted, e.g:
```csharp
// C# code here
```
If you can do what you want using AutoMapper go ahead and use it, Our built-in Auto Mapping provides a fast, intuitive mapping of matching properties and convertible types/collections, for any custom mapping you can use a Custom Converter. But it’s just an alternative, feel free to use any library you prefer.
But there’s absolutely no need for all ServiceStack projects to depend on an external 3rd Party dependency which it has no reason to use, it would only be a potential source of breaking changes and an unnecessary dependency to all projects that doesn’t use it.
Thank you for fast response. I’ve tried using Custom Converter with no success in my case.
I would prefer using ServiceStack AutoMapping over Automaper, i was just wondering if any integration was possible.
Not sure what integration you’re hoping for, they’re just Mapping libraries used within your own Service implementations, ServiceStack doesn’t even use its own built-in AutoMapping to execute your Services. You can use whichever library you prefer, your Service implementation is opaque to ServiceStack.