automapper 将每个地图源和目的地添加到字典
automapper add every map source and destination to dictionary
我有一个模型和一个视图模型
public class CategoryViewModel{
public string Serial { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
}
public class Category{
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
public Category Parent { get; set; }
}
并且 CategoryViewModel
处于树视图形状。我想用 Automapper
将 CategoryViewModel
映射到 Category
并将它们添加到字典中,如下所述:
Dictionary<string, OrganizationLevel> dic = new Dictionary<string, OrganizationLevel>();
此外,我希望获取源视图模型 serial
作为键和目标 Category
作为值,然后将它们添加到字典中,如下所示:
automapper.map<CategoryViewModel, Category>({
config =>{ dic.add( categoryViewModel.serial, category ) }
},categoryViewmodelTree)
在映射器配置中添加:
AfterMap((src, des) => dic.Add(src, des));
我有一个模型和一个视图模型
public class CategoryViewModel{
public string Serial { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
}
public class Category{
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
public Category Parent { get; set; }
}
并且 CategoryViewModel
处于树视图形状。我想用 Automapper
将 CategoryViewModel
映射到 Category
并将它们添加到字典中,如下所述:
Dictionary<string, OrganizationLevel> dic = new Dictionary<string, OrganizationLevel>();
此外,我希望获取源视图模型 serial
作为键和目标 Category
作为值,然后将它们添加到字典中,如下所示:
automapper.map<CategoryViewModel, Category>({
config =>{ dic.add( categoryViewModel.serial, category ) }
},categoryViewmodelTree)
在映射器配置中添加:
AfterMap((src, des) => dic.Add(src, des));