4
감사를 사용하여 LINQ 쿼리를 생성
나에 대한 식 트리를 만들려고 해요
원래 주어진 charecter로 시작하는 요소들을 반환한다.
IList<char> chars = new List<char>{'a','b'};
IQueryable<Dept>Depts.Where(x=> chars.Contains(x.DeptName[0]));
은 내가 예에서 선택 속성에 lamdba를 제공하는 곳은 어떤 IEnumerable을 사용할 수 원하는 :
Depts.Alpha(x=>x.DeptName, chars);
나는이 시도하지만, 전혀 운이없는 봤는데 , 어떤 도움?
public static IQueryable<T> testing<T>(this IQueryable<T> queryableData, Expression<Func<T,string>> pi, IEnumerable<char> chars)
{
// Compose the expression tree that represents the parameter to the predicate.
ParameterExpression pe = Expression.Parameter(queryableData.ElementType, "x");
ConstantExpression ch = Expression.Constant(chars,typeof(IEnumerable<char>));
// ***** Where(x=>chars.Contains(x.pi[0])) *****
// pi is a string property
//Get the string property
Expression first = Expression.Constant(0);
//Get the first character of the string
Expression firstchar = Expression.ArrayIndex(pi.Body, first);
//Call "Contains" on chars with argument being right
Expression e = Expression.Call(ch, typeof(IEnumerable<char>).GetMethod("Contains", new Type[] { typeof(char) }),firstchar);
MethodCallExpression whereCallExpression = Expression.Call(
typeof(Queryable),
"Where",
new Type[] { queryableData.ElementType },
queryableData.Expression,
Expression.Lambda<Func<T, bool>>(e, new ParameterExpression[] { pe }));
// ***** End Where *****
return (queryableData.Provider.CreateQuery<T>(whereCallExpression));
}
완벽한 덕분입니다. 나는 (IPagedList의 라인을 따라) 영숫자 페이지리스트에 대해 작업하고 있는데 이것은 값을 헤아릴 수 없을 것이다. – Chao