自动映射域类和自定义模型时,如何删除圆弧引用?

时间:2018-07-19 09:33:39

标签: asp.net-mvc automapper-5

我正在使用autommapper将域类转换为asp.net中的自定义模型,问题是automapper创建了循环 具有子对象的引用,如何删除循环引用?

 var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap<Appointment, AppointmentModel>()
                             //.ForMember(x => x.Profile.Appointments, opt => opt.Ignore())

                             //.ForPath(m => m.User.Profile, opt => opt.Ignore())
                             // .ForPath(m => m.User.Appointments, opt => opt.Ignore())
                             //  .ForPath(m => m.User.Appointments1, opt => opt.Ignore())
                             //   .ForPath(m => m.User.Appointments2, opt => opt.Ignore())
                             //     .ForPath(m => m.User.City, opt => opt.Ignore())
                             //       .ForPath(m => m.User.Claims, opt => opt.Ignore())
                             //       .ForPath(m => m.User.Employee, opt => opt.Ignore())
                             //       .ForPath(m => m.User.Logins, opt => opt.Ignore())
                             //       .ForPath(m => m.User.Physician, opt => opt.Ignore())

                             .ForMember(dest => dest.Profile,
                                    opt => opt.ResolveUsing(src => src?.Profile))
                        .ForMember(dest => dest.DoctorUser,
                                    opt => opt.ResolveUsing(src => src?.User1))
                             .ForMember(dest => dest.User,
                                    opt => opt.ResolveUsing(src => src?.User));

                    });
                    IMapper iMapper = config.CreateMapper();

                    return iMapper.Map<List<Appointment>, List<AppointmentModel>>(model?.ToList());

0 个答案:

没有答案