Ejemplo n.º 1
0
 public void SelectCount(Expression condition)
 {
     SelectNode = new CountSelectNode(this);
     if (condition != null)
     {
         WhereNodes.Add(new WhereNode(condition.GetLambda(), FromNode.Alias, this));
     }
 }
Ejemplo n.º 2
0
 public void SelectSingle(Expression condition, bool allowDefault)
 {
     AllowDefault = allowDefault;
     Take         = new ConstantNode(Expression.Constant(1), this);
     if (condition != null)
     {
         WhereNodes.Add(new WhereNode(condition.GetLambda(), FromNode.Alias, this));
     }
 }
Ejemplo n.º 3
0
        private void DoVisit(MethodCallExpression expression)
        {
            switch (expression.Method.Name)
            {
            case "Where":
                WhereNodes.Add(new WhereNode(expression.Arguments[1].GetLambda(), FromNode.Alias, this));
                Visit(expression.Arguments[0]);
                break;

            case "OrderBy":
            case "OrderByDescending":
            case "ThenBy":
            case "ThenByDescending":
                Visit(expression.Arguments[0]);
                break;

            default:
                throw new InvalidOperationException(string.Format("Method {0} is not valid for {1}", expression.Method.GetFriendlyName(), GetType().GetFriendlyName()));
            }
        }
Ejemplo n.º 4
0
 public void Where(LambdaExpression lambda)
 {
     WhereNodes.Add(new WhereNode(lambda, FromNode.Alias, this));
 }
Ejemplo n.º 5
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()));
            }
        }