【发布时间】:2012-12-18 01:49:06
【问题描述】:
我需要为AutoMapper 设置AfterMap,但我没有使用通用版本,因为我在运行时根据需要创建地图。如果我使用通用版本,我会这样做:
Mapper.CreateMap<DALEntity, BLLEntity>()
.AfterMap((DALEntity dalEntity, BLLEntity bllEntity) =>
(bllEntity as DomainEntityBase).State = DomainEntityState.Unchanged);
工作正常。直到运行时我才知道的其他地图是这样创建的:
Type BLLClassType = Type.GetType(BLLClassName);
Type DALClassType = Type.GetType(DALClassName);
Mapper.CreateMap(DALClassType, BLLClassType);
但现在我无法设置AfterMap。有什么建议么?我只需要在 AutoMapper 完成之后设置bllEntity 的State 属性。
【问题讨论】:
-
我认为这不一定有帮助,但对于运行时映射,我认为您可以使用
Mapper.DynamicMap而无需每次都创建映射。
标签: c# generics automapper