C#从ViewModel获取类对象列表

时间:2016-12-06 15:28:09

标签: c# viewmodel

我有两个类对象的数据viewModel。

 public class StudentViewModel
{
    public PeopleEntity People { get; set; }
    public PeopleUnitEntity PeopleUnit { get; set; }
}

在下面的代码中,我获得了PeopleEntity和PeopleUnitEntity

的值
IList<StudentViewModel> _stv = _StudentServicesObject.GetStudentByPersonCode(PersonCode);

我想在新的PeopleEntity对象中只存储人员列表,我该怎么办?

我尝试了如下,但它对我不起作用

 IList<PeopleEntity> _People = _StudentServicesObject.GetStudentByPersonCode(PersonCode).Select(pl => new PeopleEntity { People = pl });

错误

enter image description here

2 个答案:

答案 0 :(得分:2)

不会只是:

IList<PeopleEntity> _People = _StudentServicesObject.GetStudentByPersonCode(PersonCode).Select(pl => pl.People).ToList();

???

答案 1 :(得分:0)

返回IEnumerable,而不是IList,因此您需要将_stv设为IEnumerable或将结果转换为List。