2013-05-23 1 views
1

I는 다음과 같은 오류가 가지고LINQ는 방법 '을 인식하지 System.Collections.Generic.List`1 [선택 System.Int32]

 LINQ to Entities does not recognize the method 
'System.Collections.Generic.List`1 [System.Int32] get_st_past_enrollment_success()' 
method, and this method cannot be translated into a store expression. 

이 다음 LINQ 의해 발생

IEnumerable<subject> _subjects = (from subject in context.subjects 
          where 
           subject.enrollments.Count() < subject.sj_max_enrollment 
           && subject.sj_availability == true 
           && !this.get_st_past_enrollment_success().Contains(subject.sj_subject_id) 

          select subject); 

public List<int> get_st_past_enrollment_success() 
     { 
      return this.enrollments.Where(e => e.em_enrolled == false && e.em_result >= 50).Select(e => e.em_subject_id).ToList(); 
     } 

내가 잘못 여기서 뭐하는 거지 :

get_st_past_enrollment_success는() 목록을 반환?

답변

1

쿼리 자체에 메서드 호출이 포함되어 있으며 Entity Framework에서이 작업을 수행 할 수 없습니다. - 그 코드가 작동하는지에 영향을 미치지 않습니다,하지만 일반 규칙을 사용하는 다른 개발자에 이상한 살펴 보겠습니다 또한

var enrollments = get_st_past_enrollment_success(); 

var _subjects = from subject in context.subjects 
       where subject.enrollments.Count() < subject.sj_max_enrollment 
         && subject.sj_availability 
         && !enrollments.Contains(subject.sj_subject_id) 
       select subject; 

get_st_past_enrollment_success.NET naming conventions 위반 참고 : 목록 쿼리 이전에 인출 추출 시도 .

+0

감사합니다. 그래, 그게 알지만 SQL 명명 규칙에 따르면 테이블 이름을 나타내는 처음 두 글자에 밑줄을 사용해야한다고합니다. 그것을 해결하기 위해서는 좀 이상한 getst_past_enrollment_success를해야 할 것입니다. java의 jpa를 사용하면 C# efw로 synomyms를 만들 수 있습니다. – bicycle

+0

@bicycle :하지만 SQL을 쓰지는 않을 것입니다. C#을 쓰고 있습니다. 따라서 SQL에서 SQL 명명 규칙을 따르고 C#에서 C# 명명 규칙을 따르십시오. (개인적으로 엔티티 모델은 .NET 컨벤션을 속성 이름으로 사용합니다. 즉, SQL 필드 이름을 변경해야한다는 의미는 아닙니다.) –

+0

그러면 속성 이름을 덮어 쓰지 않고 변경할 수 있습니다. 모델을 다시로드 할 때마다? edmx 다이어그램에서? – bicycle

관련 문제