Do i need to create automapper createmap both ways?

后端 未结 4 1413
情深已故
情深已故 2021-02-05 00:08

This might be a stupid question! (n00b to AutoMapper and time-short!)

I want to use AutoMapper to map from EF4 entities to ViewModel classes.

1) If I call

<
4条回答
  •  名媛妹妹
    2021-02-05 00:44

    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. 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 telling you that a mapping doesn't exist between the source and destination type.

提交回复
热议问题