0

I have a large class with 30+ properties, and I need to map to it from a tiny class with about 6 properties that should map automatically (same name, same Type). I do not want to have to maintain a list of 24+ .Ignore()s in the mapping config, but I do want to be able to run AutoMapper's validation routine against all the rest of my mappings; I don't particularly care if this one mapping is validated, though.

I have tried ReverseMap and some of the Ignore* methods to see what might work. I thought ReverseMap would be the trick, but either I'm using it wrong or it doesn't do what I understand it to do. It does not seem to be well-documented.

For clarity:

public class LargeClass {
    // 30+ properties here
}

public class TinyClass {
    // 6 properties here that map perfectly to LargeClass
    // 4-8 properties that do not map to LargeClass, by design
}

CreateMap<TinyClass, LargeClass>(); // Will not validate, 24+ unmapped properties on Destination :(

Thank you!

pbristow
  • 1,997
  • 4
  • 26
  • 46

1 Answers1

1

ReverseMap is when you want to reverse a map from a CreateMap call.

It sounds like you need to pass in the member list you want to validate against:

CreateMap<TinyClass, LargeClass>(MemberList.Source);

This validates against the source members.

And if you need more documentation, check out the wiki!

Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69
  • Thank you. I see now where that is in the docs; I had looked for a solution there, for hours actually, but I overlooked that little blurb that had what I needed. I really love AutoMapper, so please don't take it as any disrespect when I say ReverseMap is effectively undocumented... two passing mentions in the wiki that don't, IMO, explain how to use it. – pbristow Apr 21 '17 at 12:08
  • 1
    I think it'll grow a bit more - we're looking at expanded reverse mapping in the next release, as today I don't think it works how people really want or expect it to. – Jimmy Bogard Apr 21 '17 at 21:07