2
我希望能將一個平面數據讀取器映射到一個嵌套的DTO中。運行以下代碼的名稱爲空。我做錯了什麼或者這是不可能的?是否可以使用automapper將IDataReader映射到嵌套的DTO?
class Program
{
public class Person
{
public int id { get; set; }
public Name name { get; set; }
}
public class Name
{
public string first_name { get; set; }
public string last_name { get; set; }
}
static void Main(string[] args)
{
DataTable table = CreateSampleDataTable();
Mapper.CreateMap<IDataReader, Person>();
Mapper.CreateMap<IDataReader, Name>();
var results = Mapper.Map<IDataReader, IList<Person>>(table.CreateDataReader());
}
private static DataTable CreateSampleDataTable()
{
var table = new DataTable();
table.Columns.Add("id", typeof(int));
table.Columns.Add("first_name", typeof(string));
table.Columns.Add("last_name", typeof(string));
table.Rows.Add(100, "Jeff", "Barnes");
table.Rows.Add(101, "George", "Costanza");
table.Rows.Add(102, "Stewie", "Griffin");
table.Rows.Add(103, "Stan", "Marsh");
table.Rows.Add(104, "Eric", "Cartman");
return table;
}
}