부모 엔티티의 "Any"연산자에서 사용할 수 있도록 여러 엔티티 표현식을 만들고 결합해야합니다. 코드는 다음과 같습니다.linq-to-sql 결합한 자식 표현
Expresion<Child, bool> startDateExpression;
if(String.IsNullOrEmpty(startDate)
startDateExpression = t => true;
else
startDateExpression = t => t.start_date >= startDate;
Expression<Child, bool> endDateExpression;
if(String.IsNullOrEmpty(endDate)
endDateExpression = t => true;
else
endDateExpression = t => t => t.end_date <= endDate;
....
ParameterExpression param = startDateExpression.Parameters[0];
Expression<Func<T, bool>> Combined = Expression.Lambda<Func<Child, bool>>(
Expression.AndAlso(startDateExpression.Body, endDateExpression.Body), param);
//but now I am trying to use combined expression on parent
//this line fails just to give an idea on what I am trying to do:
//filter type is IQueryable<Parent>;
var filter = filter.Where(p =>p.Children.Any(Combined));
어떻게하면됩니까? 자식 식을 부모 식으로 변환해야 할 수도 있습니다.
가 실패하는 방법 –
오류를 컴파일 - 대리인이 1 인자에게 답장을 – Victor