1.注册
/// <summary>
/// AutoMapper 注册
/// </summary>
public class AutoMapperConfig
{
/// <summary>
///
/// </summary>
public static void Config()
{
Mapper.Initialize(m =>
{
m.CreateMap<Model1, Model2>();
});
}
}
2.使用
实体中使用 [MapTo("")]特性来对属性进行映射
Model2 newModel = Mapper.Map<Model1, Model2>(model);
详细参考:https://www.cnblogs.com/ZaraNet/p/10000311.html