2017-03-10 18 views
0

람다 식 트리 조건부에 익숙하지 않습니다. 다음 코드를 사용하여 where 조건에 사용자 지정 식 트리 메서드를 사용하려고합니다. 그러나 오류가 발생했습니다. 내가 무엇입니까C# linq 쿼리 구문에서 람다 식 트리를 사용하는 방법

from c in context.customers 
join d in context.departments on c.deptid equals d.deptid 
where (CheckForCriteria(new string{}{....})) 

private Expression<Func<Customer,bool>> CheckForCriteria(IEnumerable<string> keywords) 
{ 
    var keywordGroups = keywords.Select(k => k.Split(' ')).ToArray(); 

    return customer => keywordGroups. 
          All(keywordGroup => keywordGroup. 
           All(keyword => customer.Name.Contains(keyword)))); 
} 

오류는 다음과 같습니다

Cannot implicitly convert type 'System.Linq.Expressions.Expression<Func<...>> to bool' 
Cannot convert query expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type 

사람이 내가 잘못 한 일을 식별하는 데 도움이 수 있습니까? 감사합니다.

답변

0

솔직히 말해서, 여기 내가하는 일을 100 % 확신 할 수는 없습니다. 그러나 "어디서"진술서가 작동하려면 일부 운전자 행동이 필요합니다. 따라서 "여기"대신 "선택"을 사용할 수 있습니다.

예 :

var result = from c in context.customers 
      join d in context.departments on c.deptid equals d.deptid 
      select CheckForCriteria(new [] { "..." }); 

예 (방법 체인) :

var result = (from c in context.customers 
       join d in context.departments on c.deptid equals d.deptid 
       select CheckForCriteria(new string[] { "..." })).Name).ToList(); 
:

var result = context.customers.Join(context.departments, c => c.deptid, d => d.deptid, (c, d) => new { c, d }) 
           .Select(x => CheckForCriteria(new [] { "..." })); 

는 당신이 시도 할 수 필터링 된 이름의 목록을 얻으려면