Tôi có các lớp:Automapper Danh sách copy vào danh sách
public class Person {
public int Id{ get; set ;}
public string FirstName{ get; set ;}
public string LastName{ get; set ;}
}
public class PersonView {
public int Id{ get; set ;}
public string FirstName{ get; set ;}
public string LastName{ get; set ;}
}
tôi định nghĩa này:
Mapper.CreateMap<Person, PersonView>();
Mapper.CreateMap<PersonView, Person>()
.ForMember(person => person.Id, opt => opt.Ignore());
Đó là việc cho điều này:
PersonView personView = Mapper.Map<Person, PersonView>(new Person());
tôi muốn làm cùng nhưng đối với List<Person> to List<PersonView>
nhưng tôi không tìm thấy cú pháp đúng.
Cảm ơn
Điều thú vị cần lưu ý ở đây là mẫu nguồn có thể là loại chung nhất, như 'PersonView []' và đầu ra có thể thuộc bất kỳ loại được hỗ trợ nào khác như 'IEnumerable, ICollection, IList, v.v. – Alex