我需要映射 PriorityId -> TcTaskPriorityId
Mapper.Configuration.RecognizePrefixes("TcTask");
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task{PriorityId = 1};
var te = Mapper.Map<Task, TpTasksEntity>(t);
它只是不起作用。
识别前缀适用于源对象前缀,即:
Mapper.Configuration.RecognizePrefixes("TcTask");
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task { TcTaskPriorityId = 1 };
var te = Mapper.Map<Task, TpTasksEntity>(t);
对于你的方案,可以编写自定义命名约定:
Mapper.Configuration.SourceMemberNameTransformer = s => "TcTask" + s;
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task { PriorityId = 1 };
var te = Mapper.Map<Task, TpTasksEntity>(t);
使用RecognizeDestinationPrefixes
方法。
你能试试:
Mapper.Initialize(cfg => {
cfg.RecognizePrefixes("TcTask");
cfg.CreateMap<Task, TpTasksEntity>();
});