Classes created as below:
public class Base
{
public int Id { get; set; }
}
public class Derived:Base
{
public string Name { get; set; }
}
Automapper mapping defined as:
CreateMap<DataRow, Base>()
.ForMember(m => m.Id, opt => opt.MapFrom(r => r["Id"]));
CreateMap<DataRow, Derived>()
.IncludeBase<DataRow, Base>()
.ForMember(m => m.Name, opt => opt.MapFrom(r => r["Name"]))
Output of this mapping is:
{
"Name":"ABC",
"Id":1
}
Expected result:
{
"Id":1,
"Name":"ABC"
}
I want to maintain the sequence of properties as defined in base and derived class.