Automapper副本列表列出 [英] Automapper copy List to List
本文介绍了Automapper副本列表列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些类:
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 ;}
}
我定义的:
I defined this :
Mapper.CreateMap<Person, PersonView>();
Mapper.CreateMap<PersonView, Person>()
.ForMember(person => person.Id, opt => opt.Ignore());
这是对这项工作:
PersonView personView = Mapper.Map<Person, PersonView>(new Person());
我想作相同的,但为列表<人>列出< PersonView方式>
,但我没有找到正确的语法
I'd like make the same but for List<Person> to List<PersonView>
but I don't find the right syntax.
感谢
推荐答案
一旦你创建的地图(你已经完成了,您不必重复列表),它是那么容易,因为:
Once you've created the map (which you've already done, you don't need to repeat for Lists), it's as easy as:
List<PersonView> personViews =
Mapper.Map<List<Person>, List<PersonView>>(people);
您可以阅读更多的的列表和阵列 AutoMapper文档。
You can read more in the AutoMapper documentation for Lists and Arrays.
这篇关于Automapper副本列表列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文