I have need to map PriorityId -> TcTaskPriorityId
Mapper.Configuration.RecognizePrefixes("TcTask");
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task{PriorityId = 1};
var te = Mapper.Map<Task, TpTasksEnt开发者_运维技巧ity>(t);
It just does not work.
The RecognizePrefixes works for source object prefixes, i.e.:
Mapper.Configuration.RecognizePrefixes("TcTask");
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task { TcTaskPriorityId = 1 };
var te = Mapper.Map<Task, TpTasksEntity>(t);
For your scenario you could write a custom naming convention:
Mapper.Configuration.SourceMemberNameTransformer = s => "TcTask" + s;
Mapper.CreateMap<Task, TpTasksEntity>();
Task t = new Task { PriorityId = 1 };
var te = Mapper.Map<Task, TpTasksEntity>(t);
Use RecognizeDestinationPrefixes
method.
Can you try:
Mapper.Initialize(cfg => {
cfg.RecognizePrefixes("TcTask");
cfg.CreateMap<Task, TpTasksEntity>();
});
精彩评论