protected virtual Expression VisitOrderBy(OrderByExpression node)
 {
     Append("ORDER BY");
     Visit(node.By);
     return(node);
 }
Esempio n. 2
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var expression = node.Arguments.Count > 1 ? BuildExpression(node.Arguments[1]) : null;

            switch (node.Method.Name)
            {
            case "Where":
            case "Single":
            case "SingleOrDefault":
                _where = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "Select":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.AddSelection(expression);
                break;

            case "Update":
                if (_update == null)
                {
                    _update = new UpdateExpression();
                }
                _update.AddSet(expression);
                break;

            case "Count":
                _select = new SelectExpression {
                    Selection = new CountExpression()
                };
                _where = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "First":
            case "FirstOrDefault":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.Top = Expression.Constant(1);
                _where      = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "Take":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.Top = node.Arguments[1];
                break;

            case "Skip":
                throw new NotImplementedException();

            case "OrderBy":
            case "ThenBy":
                if (_orderBy == null)
                {
                    _orderBy = new OrderByExpression();
                }
                _orderBy.AddColumn(expression, ListSortDirection.Ascending);
                break;

            case "ThenByDescending":
            case "OrderByDescending":
                if (_orderBy == null)
                {
                    _orderBy = new OrderByExpression();
                }
                _orderBy.AddColumn(expression, ListSortDirection.Descending);
                break;

            case "Contains":
            case "StartsWith":
            case "EndsWith":
            case "AssignNewValue":
                break;

            default:
                throw new NotSupportedException("Not supported method: " + node.Method.Name);
            }
            return(base.VisitMethodCall(node));
        }
Esempio n. 3
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var expression = node.Arguments.Count > 1 ? BuildExpression(node.Arguments[1]) : null;

            switch (node.Method.Name)
            {
            case "Where":
            case "Single":
            case "SingleOrDefault":
            case "StartsWith":
            case "EndsWith":
                _where = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "Select":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.AddSelection(expression);
                break;

            case "Update":
                Debugger.Break();
                if (_update == null)
                {
                    _update = new UpdateExpression();
                }
                _update.AddSet(expression);
                break;

            case "Count":
                _select = new SelectExpression {
                    Selection = new CountExpression()
                };
                _where = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "Max":
                _select = new SelectExpression {
                    Selection = new MaxExpression(expression)
                };
                break;

            case "Any":
                _select = new SelectExpression {
                    Selection = new CountExpression()
                };
                _where = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "First":
            case "FirstOrDefault":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.Top = Expression.Constant(1);
                _where      = _where == null ? expression : new WhereExpression(_where, expression);
                break;

            case "Take":
                if (_select == null)
                {
                    _select = new SelectExpression();
                }
                _select.Top = node.Arguments[1];
                break;

            case "OrderBy":
            case "ThenBy":
                if (_orderBy == null)
                {
                    _orderBy = new OrderByExpression();
                }
                _orderBy.AddColumn(expression, ListSortDirection.Ascending);
                break;

            case "ThenByDescending":
            case "OrderByDescending":
                if (_orderBy == null)
                {
                    _orderBy = new OrderByExpression();
                }
                _orderBy.AddColumn(expression, ListSortDirection.Descending);
                break;

            case "OfType":
                if (_ofType == null)
                {
                    var constantExpression = expression as ConstantExpression;
                    var param = constantExpression == null?node.Method.ReturnType.GetGenericArguments()[0] : constantExpression.Value;

                    var types = _dbSet.GetDiscriminatorValues((Type)param);
                    if (types != null)
                    {
                        _ofType = new ContainsExpression(new ColumnExpression("Discriminator"), types.Cast <Type>().Select(t => t.FullName));
                    }
                }
                break;

            case "Contains":
                break;

            case "Skip":
            case "AssignNewValue":
                throw new NotImplementedException();

            default:
                throw new NotSupportedException("Not supported method: " + node.Method.Name);
            }
            return(base.VisitMethodCall(node));
        }
 protected virtual Expression VisitOrderBy(OrderByExpression node)
 {
     Append("ORDER BY");
     Visit(node.By);
     return node;
 }