Questions tagged «automapper»

NET的基于约定的对象到对象映射器和转换器

6
使用自动映射器映射列表
我有课程: public class Person{ /* Props here */ } public class PersonViewModel { /* Props here */ } 然后列出: List<Person> people = new List<Person>(); List<PersonViewModel> peopleVM = Mapper .MapList<Person, PersonViewModel>(people); //Problem here. 正确的方法是什么?

2
自动映射器:使用ReverseMap()和ForMember()进行双向映射
我有一种情况,我想将一个实体映射到一个视图模型并返回。我必须明确指定映射,ForMember()因为它们的属性不共享完全相同的名称。这是我的班级样子的简短示例: public class PartTwo { public int Integer { get; set; } } public class PartTwoViewModel { public int PartInteger { get; set; } } 我想以这种方式使用它们: Mapper.CreateMap<PartTwo, PartTwoViewModel>() .ForMember(dst => dst.PartInteger, opt => opt.MapFrom(src => src.Integer)) .ReverseMap(); var partTwoViewModel = new PartTwoViewModel() { PartInteger = 42 }; var partTwo = …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.