I have following classes structure
public class ClassA
{
public ClassB objB;
}
Public class ClassB
{
public ListOfData objListofData;
}
public class ListOfData
{
public Employee objEmp;
}
public class Employee
{
public string FirstName;
public string LastName;
}
Return type of above hierarchy would be
"ClassA":{
"classB":{
"ListOfData":{
"employee":{
"FirstName":"David",
"LastName" :"Peter"
}
}
}
}
I want to map employee class to EmployeeViewModel where Employee firstname and lastname will be mapped to employeeViewModel FullName property. I can achieve this by following piece of code
public class EmployeeViewModel
{
public FullName;
}
CreateMap<Employee,EmployeeViewModel>()
.ForMember(dest => dest.FullName,
opts => opts.MapFrom(
src => string.Format("{0} {1}",
src.FirstName, src.LastName)));
Now How do I return back Original classA object which has mapping of EmployeeViewModel. Something like this ??
"ClassA":{
"classB":{
"ListOfData":{
"EmployeeViewModel":{
"FullName":"David Peter"
}
}
}
}