2016-12-06 7 views
1

두 클래스 개체가있는 viewModel 데이터가 있습니다. 내가 PeopleEntity 및 PeopleUnitEntityC# ViewModel에서 클래스 개체 목록 가져 오기

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

나는 새로운 PeopleEntity 개체 만 사람들 목록을 저장할 모두에 대한 값을 얻을 코드를 다음에서

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

, 내가 그걸 어떻게 할 수 ???

나는 다음과 같은 시도했지만 나를 위해 작동하지 않습니다

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

오류

enter image description here

+0

왜 안 되니 .ToList() –

답변

2

은 그냥하지 않을까요 :

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

???

+0

그래, 시도해 봤다. 내 질문에 대한 오류를 스크린 샷으로 참조한다. – toxic

+0

.ToList()를 끝에 추가한다. – dviljoen

+0

또는 _stv의 정의를 IEnumerable로 변경하십시오. – dviljoen

0

여기서 IList가 아닌 IEnumerable을 반환하므로 _stv에 IEnumerable을 만들거나 결과를 List로 변환해야합니다.

+0

이미 말한 내용을 의미합니다. –

+0

죄송합니다.이 답변을 제공 할 때 의견이 없습니다. –