Automapper Mapping Multiple Properties to Single Property

前端 未结 2 1332
难免孤独
难免孤独 2021-01-18 14:01

I am need help mapping my Domain Object to a ViewModel for use with my C#/MVC App

In the FormAnswer Class there can only be 1 Answer Type (AnswerCurrency, AnswerDate

2条回答
  •  别那么骄傲
    2021-01-18 14:51

    You could use a custom mapping lambda method but it seems like you would need more logic here. A custom resolver seems to be a good option in this case.

    See Automapper wiki

    https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-resolvers

    In the mapping options you can specify a opt.ResolveUsing() where TResolver inherits from ValueResolver

    Also, if I need to know how to do something with Automapper I find that the unit tests provide very rich documentation.

    Hope that helps.

提交回复
热议问题