开发者

AutoMapper - How do I map some dto objects into one domain object?

I am having an issue using AutoMapper to map some DTO objects (abstract object with inheritance) to one domain object.

Here are my objects:

  • public class Product
  • public abstract class ABaseProductDTO
  • public class MinimalProductDTO : ABaseProductDTO
  • public class BasicProductDTO : MinimalProductDTO
  • public class MaximalProductDTO : BasicProductDTO
  • public class NodeDTO { ABaseProductDTO }
  • public class Node { Product }

The Node contains a Product and accordingly the NodeDTO contains an ABaseProductDTO in it which I want to map to a specific dto product according to an enum.

I know that if there's a match for each DTO I can use 'Include' but this is not the case..

So my question is how do I map 3 dto objects into one domain object开发者_开发问答? ('MinimalProductDTO', 'BasicProductDTO', 'MaximalProductDTO' into 'Product')???

Thanks


I'm not sure if there is dynamic mappings like that. You might have to check the ENUM of the BASE object and then call the correct mapping for the NodeDTO. Not elegant but I would work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜