0
我對這個表達式業務很陌生。我在此示例之後建模:https://msdn.microsoft.com/en-us/library/vstudio/bb882637(v=vs.110).aspxMethodCallExpression沒有正確設置訂單
我試圖獲得滿足特定名稱的辦公室列表。代碼工作到我需要通過設置順序。我不斷收到此錯誤:
ParameterExpression of type 'DB.Office' cannot be used for delegate parameter of type 'System.String'
這裏是代碼
IQueryable<Office> offices = GetAllOffices();
ParameterExpression pe = Expression.Parameter(typeof(Office), "Office");
Expression left = Expression.Property(pe, typeof(Office).GetProperty("OfficeName"));
Expression right = Expression.Constant(filterRequest.Filters.Value);
Expression e1 = Expression.Equal(left, right);
Expression predicateBody = e1;
MethodCallExpression whereCallExpression = Expression.Call(
typeof(Queryable),
"Where",
new Type[] { offices.ElementType },
offices.Expression,
Expression.Lambda<Func<Office, bool>>(predicateBody, new ParameterExpression[] { pe }));
MethodCallExpression orderByCallExpression = Expression.Call(
typeof(Queryable),
"OrderBy",
new Type[] { offices.ElementType, offices.ElementType },
whereCallExpression,
Expression.Lambda<Func<string, string>>(pe, new ParameterExpression[] { pe }));
IQueryable<string> results = offices.Provider.CreateQuery<string>(orderByCallExpression);