我的 N 层项目中有不同的模型,我想使用 Automapper 进行映射。
我做了如下
public ServicesProfile()
{
CreateMap<State, StateModel>();
CreateMap<StateModel, State>();
CreateMap<City, CityModel>();
CreateMap<CityModel, City>();
//.... Some 100 models
}
是否有任何简单的方法可以按照约定进行映射(以模型结尾,其余名称相同)?
最佳答案
尝试使用
CreateMap<State, StateModel>().ReverseMap();
参见:https://github.com/AutoMapper/AutoMapper/blob/master/docs/Reverse-Mapping-and-Unflattening.md
关于c# - 如何在自动映射器中使用模式映射源和目的地?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50706949/