Convierta DataRow a objeto con AutoMapper
Puedo asignar correctamente desde IDataReader a una Lista de objetos, pero cuando quiero tomar un DataRow, no parece funcionar como se esperaba.
¿Me estoy perdiendo algo simple aquí?
[TestFixture]
public class AutomapperTest
{
[Test]
public void TestMethod1()
{
DataTable dt = new DataTable("contact");
dt.Columns.Add("FirstName");
dt.Columns.Add("LastName");
dt.Columns.Add("Line1");
dt.Columns.Add("Line2");
dt.Columns.Add("Line3");
dt.Columns.Add("Suburb");
dt.Columns.Add("State");
dt.Columns.Add("Postcode");
DataRow row = dt.NewRow();
row.ItemArray = new [] { "Little", "Johnny",
"1 Random Place", "", "",
"Windsor", "Qld", "4030" };
var dest = Mapper.DynamicMap<myObject>(row);
Assert.AreEqual(row["FirstName"], "Little");
Assert.IsNotNull(dest);
Assert.AreEqual(dest.FirstName, "Little");
}
}
Tipo de destino:
public class myObject
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Line3 { get; set; }
public string Suburb { get; set; }
public string State { get; set; }
public string Postcode { get; set; }
}