c# - 如何在自动映射器中使用模式映射源和目的地?

标签 c# automapper

我的 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/

相关文章:

c# - linq 中的 System.Guid.NewGuid() 选择

c# - .Net 中嵌套对象的最佳实践是什么?

c# - 如何将此循环写成一行?

automapper - 使用 Automapper 在子类映射中忽略基类属性的问题

c# - AutoMapper - 展平/展平列表

c# - WPF 网格 IsEnabled 使用 ValueConverter

c# - Microsoft.Office.Interop.Excel.WorksheetFunction 不包含 excel 中的所有函数

automapper - 从具有整数属性的模型投影到具有 Enum 属性的类

c# - automapper 继承 Profile 返回 json 中的额外属性

asp.net-mvc-3 - 使用Automapper/EF代码优先进行数据库更新