0
假設我有以下類Automapper和嵌套對象
public class Parent {
public int ParentId { get; set; }
public List<Child> Children{get; set; }
// other properties
}
public class Child {
public int ChildId { get; set; }
// other properties
}
public class ParentVm {
public int ParentId { get; set; }
public List<ChildVm> Children{get; set; }
// other properties
}
public class ChildVm {
public int ParentId { get; set; }
public int ChildId { get; set; }
// other properties
}
Parent parent = /*something*/
var parentVm = Mapper.Map<ParentVm>(parent);
在ChildVm
,有物業ParentId
。我該如何傳播這個值來使用automapper?
它不通過你的問題,你試圖映射'ChildVm'.'ParentId'任何東西出現。另外,如果您嘗試創建'ParentVm',則該Mapper.Map'命令顯示爲反向,因爲該行將創建一個'Parent'對象。 真正的用例是否試圖將具有'Child'對象的'Parent'對象映射到具有'ChildVm'對象的'ParentVm'?並且讓'Parent'.'ParentId'屬性傳播到'ChildVm'.'ParentId'屬性? –