1
我具有以下的類結構Automapper映射嵌套對象
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;
}
上述層次結構的返回類型將是
"ClassA":{
"classB":{
"ListOfData":{
"employee":{
"FirstName":"David",
"LastName" :"Peter"
}
}
}
}
我要地圖僱員類EmployeeViewModel其中僱員名字和姓氏將被映射到employeeViewModel FullName屬性。我可以通過下面的代碼段
public class EmployeeViewModel
{
public FullName;
}
CreateMap<Employee,EmployeeViewModel>()
.ForMember(dest => dest.FullName,
opts => opts.MapFrom(
src => string.Format("{0} {1}",
src.FirstName, src.LastName)));
現在怎麼辦就回國了具有EmployeeViewModel的映射原始ClassA的對象實現這一目標。像這樣?
"ClassA":{
"classB":{
"ListOfData":{
"EmployeeViewModel":{
"FullName":"David Peter"
}
}
}
}