[英]automapper add every map source and destination to dictionary
我有一個 model 和一個視圖 model
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
是 treeview 形狀。 我想使用Automapper
將 map CategoryViewModel
到Category
並將它們添加到字典中,如下所述:
Dictionary<string, OrganizationLevel> dic = new Dictionary<string, OrganizationLevel>();
另外,我想獲取源視圖 model serial
作為鍵和目標Category
作為值,然后將它們添加到字典中,如下所示:
automapper.map<CategoryViewModel, Category>({
config =>{ dic.add( categoryViewModel.serial, category ) }
},categoryViewmodelTree)
在映射器配置中添加:
AfterMap((src, des) => dic.Add(src, des));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.