AutoMapper用法
可在每层这样写一个类,整合每个实体类的映射
public class AutoMapperHelper
{
public static void Register()
{
Mapper.Initialize(x => x.AddProfile<ModelProfile>());
}
}
public class ModelProfile : Profile
{
public override string ProfileName
{
get
{
return GetType().Name;
}
}
protected override void Configure()
{
CreateMap<AccessoryDto, i_accessory>()
.ForMember(d => d.CategoryID, opt => opt.MapFrom(s => s.CategoryL2ID));
}
}
然后在使用中先调用一下,注册映射关系类
AutoMapperHelper.Register();

浙公网安备 33010602011771号