简体   繁体   中英

How do you remove OrderBy expression from an ExpressionTree using a ExpressionVisitor?

The Orderby statment is not supported by the Azure Table storage linq provider I have an Expression like

.Where(t => (t.RowKey.CompareTo("U_") > 0)).OrderBy(user => user.UserName)

i'm trying to remove .OrderBy(user => user.UserName) from the expression tree

I would also like the visitor to remove the orderby statment from the following expression

.Where(t => (t.RowKey.CompareTo("U_") > 0)).OrderBy(user => user.UserName).Take(10)

will become

.Where(t => (t.RowKey.CompareTo("U_") > 0)).Take(10)

Here's a visitor implementation.

class OrderByRemovalVisitor : ExpressionVisitor
{

    protected override Expression VisitMethodCall(MethodCallExpression node)
    {

        if (node.Method.Name == "OrderBy" && node.Method.DeclaringType == typeof(Queryable))
            return node.Arguments[0];
        else
            return base.VisitMethodCall(node);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM