-4

I'm starting to use AutoMapper for my project. For this I want to do the following 'one-to-many' mapping:

Source:

public class Team
{
    int Id { get; set; }
    string TeamName { get; set; }
    List<Person> Member { get; set; }
}
public class Person
{
    int Id { get; set; }
    string Name { get; set; }
    string EyeColor { get; set; }
}

Destination:

public class TeamDetailsViewModel
{
    int Id { get; set; }
    string TeamName { get; set; }
    List<MemberViewModel> Members { get; set; }
}
public class MemeberViewModel
{
    int Id { get; set; }
    string EyeColor { get; set; }
}

My question is like this question, but I want to map a class instead of List<int>.

How to proceed with AutoMapper? Is this possible?

wovano
  • 3,264
  • 4
  • 18
  • 43
Milad Ahmadi
  • 61
  • 1
  • 4
  • 1
    Rather than [deleting and reposting](https://stackoverflow.com/questions/72412083/one-to-many-relation-automapper), please edit and improve your question. I'll repeat my same advice. – gunr2171 May 28 '22 at 01:28
  • 1
    All that has been posted is a program description, but that doesn't tell us what _problem_ you're having. What have you tried, and what troubles did you encounter? Please [edit] your post to include a [valid question](/help/how-to-ask) that we can answer. Reminder: make sure you know what is [on-topic](/help/on-topic); asking us to write the program for you, opinions, and external links are off-topic. – gunr2171 May 28 '22 at 01:28
  • The problem with simply deleting and reposting a question is that you don't improve the problems that led to the original one being downvoted and closed. – DiplomacyNotWar May 28 '22 at 01:34
  • I also don't see evidence of needing to map one to many. It seems like you want to map Team to TeamDetailsViewModel, and also be able to map Person to MemberViewModel (not list of - Automapper handles them automatically). It's not clear where "many" comes in, or what trouble you're having with this mapping. – DiplomacyNotWar May 28 '22 at 01:37
  • My question is https://stackoverflow.com/a/6874096/16180500, but I want to map a class instead of List – Milad Ahmadi May 28 '22 at 01:45
  • You don't map List in automapper, you just map x. Automapper knows how to make a List out of a List if you tell it how x maps to y – Caius Jard May 28 '22 at 03:25

0 Answers0