Automapper - RecognizePrefixes not working

I need to map PriorityId -> TcTaskPriorityId

 Mapper.Configuration.RecognizePrefixes("TcTask");
 Mapper.CreateMap<Task, TpTasksEntity>();

 Task t = new Task{PriorityId = 1};          
 var te = Mapper.Map<Task, TpTasksEntity>(t);

It just doesn't work.

+3
source share
3 answers

Use the method RecognizeDestinationPrefixes.

+2
source

RecognizePrefixes works for prefixes of the source object, 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 can write the usual 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);
+3
source

Can you try:

Mapper.Initialize(cfg => {
    cfg.RecognizePrefixes("TcTask");
    cfg.CreateMap<Task, TpTasksEntity>();
});
+1
source

All Articles