C#从ViewModel获取类对象列表

C#从ViewModel获取类对象列表,c#,viewmodel,C#,Viewmodel,我有两类对象的数据视图模型 public class StudentViewModel { public PeopleEntity People { get; set; } public PeopleUnitEntity PeopleUnit { get; set; } } 在下面的代码中,我得到PeopleEntity和PeopleUnitEntity的值 IList<StudentViewModel> _stv = _StudentServicesObject

我有两类对象的数据视图模型

 public class StudentViewModel
{
    public PeopleEntity People { get; set; }
    public PeopleUnitEntity PeopleUnit { get; set; }
}
在下面的代码中,我得到PeopleEntity和PeopleUnitEntity的值

IList<StudentViewModel> _stv = _StudentServicesObject.GetStudentByPersonCode(PersonCode);
IList\u stv=\u StudentServicesObject.GetStudentByPersonCode(PersonCode);
我只想在新的PeopleEntity对象中存储人员列表,我该怎么做

我试着如下,但它不适合我

 IList<PeopleEntity> _People = _StudentServicesObject.GetStudentByPersonCode(PersonCode).Select(pl => new PeopleEntity { People = pl });
IList\u People=\u StudentServicesObject.GetStudentByPersonCode(PersonCode).Select(pl=>newpeopleentity{People=pl});
错误

难道不是:

IList<PeopleEntity> _People = _StudentServicesObject.GetStudentByPersonCode(PersonCode).Select(pl => pl.People).ToList();
IList\u People=\u StudentServicesObject.GetStudentByPersonCode(PersonCode)。选择(pl=>pl.People.ToList();

???

其中返回IEnumerable,而不是IList,因此您需要将_stv设置为IEnumerable或将结果转换为列表。

是的,我尝试过,请在问题更新中使用screenshotAdd.ToList()引用错误。或者将_stv的定义更改为IEnumerablehy not.ToList()很抱歉,当我在评论中没有给出答案的地方提供了这个答案!