예제 #1
0
        private void DoVisit(MethodCallExpression expression)
        {
            switch (expression.Method.Name)
            {
            case "Where": _actions.Push(() => WhereNodes.Add(new WhereNode(expression.Arguments[1].GetLambda(), FromNode.Alias, this)));
                Visit(expression.Arguments[0]);
                break;

            case "OrderBy":
            case "ThenBy":
                _actions.Push(() => OrderBy(expression.Arguments[1], SortDir.Asc));
                Visit(expression.Arguments[0]);
                break;

            case "OrderByDescending":
            case "ThenByDescending":
                _actions.Push(() => OrderBy(expression.Arguments[1], SortDir.Desc));
                Visit(expression.Arguments[0]);
                break;

            case "First":
            case "Single":
                _actions.Push(() => SelectSingle(expression.GetArgumentOrDefault(1), false));
                Visit(expression.Arguments[0]);
                break;

            case "FirstOrDefault":
            case "SingleOrDefault":
                _actions.Push(() => SelectSingle(expression.GetArgumentOrDefault(1), true));
                Visit(expression.Arguments[0]);
                break;

            case "Count":
                _actions.Push(() => SelectCount(expression.GetArgumentOrDefault(1)));
                Visit(expression.Arguments[0]);
                break;

            case "Select":
                Select(expression);
                break;

            case "Sum":
                _actions.Push(() => SelectNode = new SumSelectNode(expression.Arguments[1].GetLambda(), this));
                Visit(expression.Arguments[0]);
                break;

            case "Skip":
                _actions.Push(() => Skip = For(expression.Arguments[1]));
                Visit(expression.Arguments[0]);
                break;

            case "Distinct":
                _actions.Push(() => Distinct = true);
                Visit(expression.Arguments[0]);
                break;

            case "Take":
                _actions.Push(() => Take = For(expression.Arguments[1]));
                Visit(expression.Arguments[0]);
                break;

            default: throw new InvalidOperationException(string.Format("Don't know how to parse method {0}", expression.Method.GetFriendlyName()));
            }
        }