Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

429
Views
cómo mapa múltiple en automapper

Recientemente me reuní con un automapper. Tengo una pregunta, ¿cómo puedo mapear varios objetos de mi repositorio en un DTO?

 public QuestionProfile() { CreateMap<Question, GrammarQuestionDTO>() .ForMember(g => g.Question, q => q.MapFrom(source => source.Text)).ReverseMap(); CreateMap<List<GrammarQuestionDTO>, TestDTO>() .ForMember(t => t.GrammarQuestion, g => g.MapFrom(source => source)).ReverseMap(); CreateMap<Question, AuditionQuestionDTO>() .ForMember(a => a.Question, q => q.MapFrom(source => source.Text)) .ForMember(a => a.Url, q => q.MapFrom(source => source.AudioFile.Url)).ReverseMap(); CreateMap<List<AuditionQuestionDTO>, TestDTO>() .ForMember(t => t.AuditionQuestion, a => a.MapFrom(source => source)).ReverseMap(); }

¿Cómo puedo mapear todos estos 4 objetos?

 public async Task<TestDTO> GenerateTest(LevelType level) { var grammarQuestions = await _questionRepository.GetGrammarQuestionAsync(level); var auditionQuestions = await _questionRepository.GetAuditionQuestionAsync(level); var essayTopic = await _questionRepository.GetEssayTopicAsync(level); var speakingTopic = await _questionRepository.GetSpeakingTopicAsync(level); var test = _mapper.Map<TestDTO>(grammarQuestions); test = _mapper.Map(test, auditionQuestions); //there will be a conversion error return _mapper.Map<TestDTO>(grammarQuestions); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe mapearlo sin lista, solo mapéelo uno a uno y AutoMapper manejará las colecciones:

 CreateMap<AuditionQuestionDTO, TestDTO>() .ForMember(t => t.AuditionQuestion, a => a.MapFrom(source => source.<PropertyName>)).ReverseMap();

Y luego en el mapa deberías:

 test = _mapper.Map<List<AuditionQuestionDTO>>(test, auditionQuestions);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!