2013-02-19 5 views
3

ScanningDepartments 테이블을 쿼리하여 부서를 가져 오는 GetScanningLogOnSettings()을 호출하고 ApplicationLogOnModel의 인스턴스를 만들고 쿼리 된 결과를 ApplicationLogOnModel 내의 변수에 할당 한 다음 그 결과를 반환합니다. 목록에 변환과 약간의 문제가 발생하고IQueryable 목록을 일반 목록으로 변환 하시겠습니까?

"묵시적 타입 변환 할 수 없습니다 'System.Linq.IQueryable<System.Collections.Generic.List<char>>'System.Collections.Generic.List<Models.Department>'

하려고 당신은

답변

7

:

private ApplicationLogOnModel GetScanningLogOnSettings() 
    { 
     var mesEntity = new MESEntities(); 
     var departments = from dept in mesEntity.ScanningDepartments 
         select dept.Department.ToList(); 

     ApplicationLogOnModel depts = new ApplicationLogOnModel() 
     { 
      Department = departments 
     }; 

     return depts; 
    } 

그것은 저를 제공합니다. 괄호가 누락되었습니다 :

코드에서 ToList()dept.Department으로 호출하고 전체 쿼리를 호출하지 않습니다.

+0

"이제 System.Collections.Generic.List 을 'System.Collections.Generic.List '형식으로 암시 적으로 변환 할 수 없습니다. –

+0

@ MarkSaluta :이 질문의 범위가 아닌 다른 문제입니다. 'dept.Department'는 문자열을 반환하고 'ApplicationLogOnModel.Department'는 문자열 목록이 아니라'Models.Department' 인스턴스의 목록입니다. –

관련 문제