gpt4 book ai didi

c# - Automapper - RecognizePrefixes 不起作用

转载 作者:行者123 更新时间:2023-11-30 14:39:53 25 4
gpt4 key购买 nike

我需要映射 PriorityId -> TcTaskPriorityId

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

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

它就是行不通。

最佳答案

RecognizePrefixes 适用于源对象前缀,即:

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);

关于c# - Automapper - RecognizePrefixes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5989289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com