I'm mapping csv file with School records using CsvHelper The end result should be list of Schools. Similar issue can be found here
public class School
{
public IList<Student> Students{ get; set; }
}
public class Student
{
public StudentRef Reference{ get; set; }
}
public class StudentRef
{
public string RefNumber{ get; set; }
}
One of the columns found in the CSV file is SRef which should be linked to StudentRef.RefNumber
public sealed class StudentRefMap : CsvClassMap<StudentRef>
{
public StudentRefMap ()
{
Map(m => m.RefNumber).Name("SRef");
}
}
public sealed class StudentMap : CsvClassMap<Student>
{
public StudentMap ()
{
References<StudentRefMap >(m => m.Reference);
}
}
public sealed class SchoolMap : CsvClassMap<School>
{
public SchoolMap ()
{
//References<StudentMap>(m => m.Students);//doesn't work
Map(m => m.Students)
.ConvertUsing(row => new List<Student>
{row.GetRecord<Student>()}); // doesn't work
}
}
I want to map csv file with list of Schools
, however one columns is referring to StudentRef
so using CSVHelper, how can i achieve that?