Rodrigo Kono
Rodrigo Kono

Reputation: 1

OrderBy with Linq.Expression

I have a problem to create a sort expression.

I have an expression of type Expression<Func<Products, bool>> that already contains a query expression. I am wanting to do the query ordering, but did not succeed.

Below, in CreateSortExpression method has a error:

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;
}

Error message 'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Has anyone gone through this could help me? Thanks.

Upvotes: 0

Views: 216

Answers (1)

SLaks
SLaks

Reputation: 887205

You're trying to build an expression to pass to OrderBy().
You don't want to call OrderBy() in that expression; you would want something like p => p.Something

Upvotes: 1

Related Questions