新增dto
public class UserDto : EntityDto<int> { public string UserNo { get; set; } public string UserName { get; set; } public int RoleId { get; set; } public string Password { get; set; } }
新增profile
public class UserProfile : Profile { public UserProfile() { CreateMap<User, UserDto>(); } }
在applicationmodule中使用,并添加profile中
[DependsOn( typeof(AbpDddApplicationModule), typeof(AbpAutoMapperModule), typeof(MVCEntityFrameWorkModule) )] public class MVCApplicationModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { Configure<AbpAutoMapperOptions>(opt => { opt.AddProfile<UserProfile>(); }); } }
在service中使用
public async Task<UserDto> getAsync(string UserNo, string password) { var user = await _users.GetAsync(m => m.UserNo == UserNo && m.Password == password); return ObjectMapper.Map<User, UserDto>(user); }
到此为止。