c# - How to access OrderBy clause from MethodCallExpression -
i have custom linq provider processes methodcallexpression has orderby clause inside it. how can hold of orderby clause may process it?
i figured out, here how.
public class querycontext<t> { void execute(methodcallexpression dsqueryexpression) { var orderbyfinder = new orderbyfinder(); var orderbyexpression = orderbyfinder.getorderby(dsqueryexpression); // .. continue on processing orderby expression } } internal class orderbyfinder : expressionvisitor { methodcallexpression _orderbyexpression; public methodcallexpression getorderby(expression expression) { visit(expression); return _orderbyexpression; } protected override expression visitmethodcall(methodcallexpression expression) { if (expression.method.name == "orderby") _orderbyexpression = expression; visit(expression.arguments[0]); return expression; } }
Comments
Post a Comment