Как восстановить циклическую ссылку, когда автоматизированные доменные классы и пользовательская модель?

Я использую 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 ответов

Другие вопросы по тегам