2013-10-21 22 views
0

我有一個問題來創建一個排序表達式。OrderBy與Linq.Expression

我有一個表達式Expression<Func<Products, bool>>已經包含查詢表達式。 我想做查詢排序,但沒有成功。

下面,CreateSortExpression方法有一個錯誤:'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable,System.Func)' 不能從所述推斷

private Expression<Func<Products, bool>> CreateOrderQuery(Expression<Func<Products, bool>> condition, descriptorOrder item) 
{   
    condition= condition.AndAlso(CreateSortExpression(item.PropertyName));   

    return condition; 
} 

private Expression<Func<Products, bool>> CreateSortExpression(string p) 
{ 
    Expression<Func<Products, bool>> condition = products => 
      p.OrderBy(products.Options.price); 

    return condition; 
} 

錯誤消息用法。嘗試明確指定類型參數。

有沒有人經歷過這可以幫助我? 謝謝。

+0

你試圖調用'OrderBy'你的'字符串p'? – user2674389

+0

是的,說屬性將根據lambda上下文進行排序沒有什麼意義。但我無法撥打OrderBy .. –

回答

1

您正試圖建立一個表達式傳遞給OrderBy()
您不想在該表達式中調用OrderBy();你想要的東西像p => p.Something

+0

Hi @SLaks。是的,我試圖建立一個表達式傳遞給OrderBy()。 –