3

Let us say my domain object can contain a bunch of objects like this:

List<Thing> Things

where Thing is defined like this:

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 the 'relevant bits' in the DTO?

Thanks.

Christian

James Kolpack
  • 9,331
  • 2
  • 44
  • 59
cs0815
  • 16,751
  • 45
  • 136
  • 299

1 Answers1

1

By writing custom resolver, i guess.

That's quite unusual requirement - to lose binding between id and name.


I think you are right. sorry I am still learning about the dto/viewmodel mapping. Do you think it is acceptable to put a domain object inside a DTO as there is not much point in creating a dto for Thing?

Do not mix domain model inside view model. You will regret that next week (i did for sure...).

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;}
}

Here You can find some more thoughts about view model.

Community
  • 1
  • 1
Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195
  • >That's quite unusual requirement - to lose binding between id and name yeah I think you are right. sorry I am still learning about the dto/viewmodel mapping. Do you think it is acceptable to put a domain object inside a DTO as there is not much point in creating a dto for Thing? – cs0815 Mar 15 '10 at 13:57