2012-09-27 1 views
6

내 문제는 ToLinq() 메소드입니다 arrayIndex n을왜 첫 번째 쿼리 .ToList()는 작동하지만 두 번째 쿼리는 작동하지 않습니까? LINQ 표현의</p> <p>(노드 유형 : 문제없이 첫 번째 요청 작업,하지만 두 번째는 나에게 같은 예외를주는 이유</p>이 <p>내가 understind하지 않습니다

  var q = from a in ctx.ImmImmobilisations select a; 
      q = q.Where(x => x.CodeEntite  == "EDEF"); 
      q = q.Where(x => x.CodeAffectation == "000001"); 
      q = q.Where(x => x.Unite   == "ITS"); 
      q = q.OrderBy(x => x.CodeImmobilisation); 
      List<ImmImmobilisation> res = q.ToList(); 

      var query = from e in ctx.ImmImmobilisations select e; 
      if (!string.IsNullOrEmpty(args[0])) query = query.Where(x => x.CodeEntite  == args[0]); 
      if (!string.IsNullOrEmpty(args[1])) query = query.Where(x => x.CodeAffectation == args[1]); 
      if (!string.IsNullOrEmpty(args[2])) query = query.Where(x => x.CodeFamille  == args[2]); 
      if (!string.IsNullOrEmpty(args[3])) query = query.Where(x => x.CodeCCout  == args[3]); 
      if (!string.IsNullOrEmpty(unite)) query = query.Where(x => x.Unite  == unite); 
      query = query.OrderBy(x => x.CodeImmobilisation); 
      var ress = query.ToList(); 

답변

1

귀하의 예외는 확실히 명시 적으로 문제를 말한다) 엔티티에 LINQ에서 지원되지 않습니다 : 당신은 L2Entities 표현의 내부 배열 요소를 사용할 수 없습니다.

3

엔티티에 LINQ가있는 인덱서를 사용할 수 없습니다. 인덱스의 값을 새 변수에 저장해야합니다. 이 같은

:

var arg1 = args[0];  
if (!string.IsNullOrEmpty(arg1)) query = query.Where(x => x.CodeEntite == args1); 
0

또한이 방법 Equals 메서드를 사용하여 얻을 수 있습니다

if (!string.IsNullOrEmpty(args[0])) 
    query = query.Where(x => Equals(x.CodeEntite, args[0])); 
관련 문제