且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我是否需要创建automapper createmap两者兼得?

更新时间:2021-09-16 09:08:08

在AutoMapper你有一个源类型和目标类型。所以,你将只能如果你有一个相应的CreateMap这种源类型和目标类型之间的映射。因此,要回答你的问题:

In AutoMapper you have a Source type and a Destination type. So you will be able to map between this Source type and Destination type only if you have a corresponding CreateMap. So to answer your questions:


  1. 您不要的需要的定义反向映射。你所要做的仅仅是,如果你打算映射回。

  2. 是的,你需要调用CreateMap表明,这些类型是可映射的,否则,当你调用一个会抛出异常地图< TSource,TDest> 告诉你一个映射源和目的地之间的类型不存在。

  1. You don't need to define the reverse mapping. You have to do it only if you intend to map back.
  2. Yes, you need to call CreateMap to indicate that those types are mappable otherwise an exception will be thrown when you call Map<TSource, TDest> telling you that a mapping doesn't exist between the source and destination type.