Automapper - how to display a list of objects

Say my domain object may contain a bunch of these objects:

List<Thing> Things

where thing is defined as follows:

class Thing
(
    public int ThingId { get; set; }
    public string ThingName { get; set; }
)

My DTO contains

List<string> ThingIds;
List<string> ThingNames;

The question is, how can I use automapper to map Things to "corresponding bits" in the DTO?

Thank.

Christian

+3
source share
1 answer

When writing a custom converter , I think.

This is a rather unusual requirement - to lose the binding between id and name.


I think you're right. sorry, I'm still learning about dto / viewmodel mapping. Do you find it acceptable to place a domain object inside a DTO, since it makes no sense to create a dto for Thing?

. , ( ...).

class Thing {
    public int ThingId { get; set; }
    public string ThingName { get; set; }
    public string UnnecessaryProp {get;set;}
}

class ThingViewModel {
    public int ThingId { get; set; }
    public string ThingName { get; set; }
}

class MyView {
    public IEnumerable<ThingViewModel> Things {get;set;}
}

.

+1

Source: https://habr.com/ru/post/1736997/


All Articles