Q:

How to map with comma delimited string or int to IEnumerable using automapper

I have this a result set of IEnumerable from the database given
public class Student
{
    public int StudentId { get; set; }
    public int Name { get; set; }
    public string SubjectIds { get; set; } //Comma delimitted string of subject ID
    public string Grades { get; set; } //Comma delimitted string of subject ID
}

How do I map it with IEnumerable given
public class StudentListItemDto
{
    public int StudentId { get; set; }
    public int StudentName { get; set; }
    public IEnumerable<SubjectGradeDto> Tags { get; set; }
}

Given SubjectGradeDto
public class SubjectGradeDto 
{
    public int SubjectId { get; set; }
    public string Grade { get; set; }
}

I would also appreciate linq solutions

A:

If 'students' is given by DB, so:
    var mappedStudents = students.Select(student =>
      new StudentListItemDto
      {
          StudentId = student.StudentId,
          StudentName = student.Name,
          Tags = student.SubjectIds.Split(',').Select( (subject, i) => new SubjectGradeDto { SubjectId = int.Parse(subject), Grade = student.Grades.Split(',')[i] })
      });

