I have a model and a view 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; }
}
and the CategoryViewModel
is in treeview shape. I want to map CategoryViewModel
to Category
with Automapper
and also add them to a dictionary as mentioned below:
Dictionary<string, OrganizationLevel> dic = new Dictionary<string, OrganizationLevel>();
Also, I want ot get the source view model serial
as key and destination Category
as value then add them to dictionary something like this:
automapper.map<CategoryViewModel, Category>({
config =>{ dic.add( categoryViewModel.serial, category ) }
},categoryViewmodelTree)
in mapper config add:
AfterMap((src, des) => dic.Add(src, des));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.