2
我有一个名为ActionResult的实体,我的方法沿着应用程序返回。现在,我想它是在该对象的数组正确的位置映射在一个的ActionResult返回的对象......AutoMapper映射对象到数组
public class Core
{
public Employee[] Employees = new[] {
new Employee {
Name = "Jack",
Age = 21,
Salary = 1000
},
new Employee {
Name = "Carl",
Age = 35,
Salary = 1000
},
new Employee {
Name = "Tom",
Age = 41,
Salary = 1000
},
};
}
public class ActionResult
{
public string ActionID { get; set; }
public Employee Employee { get; set; }
}
public class Employee
{
public String Name { get; set; }
public int? Age { get; set; }
public int? Salary { get; set; }
public int? Level { get; set; }
}
public ActionResult MethodThatReturnsActionResultWithAnEmployee()
{
return new ActionResult {
ActionID = new Guid().ToString(),
Employee = new Employee {
Name = "Carl",
Age = 35,
Salary = 7000,
Level = 1
}
};
}
现在,你可以看到我想要做的是采取的是从返回的员工方法,并搜索Core中的Employees数组,并使用AutoMapper使用新的给定数据对其进行更新。
我想你提供了帮助但遗憾的是它不映射属性休息... IDK的为什么 –
@DanialEugen在第二个方法,如果你有核心的一些性质应被映射的话,我想您应该在类型转换器中手动映射它们(因为对象使用自定义类型转换器映射)。员工的所有属性都应该映射而没有问题。 –