开发者

Automapper - RecognizePrefixes doesn't work

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>();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜