ChangeWhereAndColumns() 공개 메소드

public ChangeWhereAndColumns ( Expression where, IReadOnlyList columns, bool forUpdate = null ) : SqlSelectExpression
where System.Linq.Expressions.Expression
columns IReadOnlyList
forUpdate bool
리턴 SqlSelectExpression
예제 #1
0
        protected override Expression VisitSelect(SqlSelectExpression selectExpression)
        {
            List<SqlColumnDeclaration> newColumns = null;

            for (var i = 0; i < selectExpression.Columns.Count; i++)
            {
                var column = selectExpression.Columns[i];
                var visitedColumnExpression = this.Visit(column.Expression);

                if (visitedColumnExpression.Type.GetUnwrappedNullableType() == typeof(bool) && !(visitedColumnExpression is BitBooleanExpression))
                {
                    if (newColumns == null)
                    {
                        newColumns = new List<SqlColumnDeclaration>(selectExpression.Columns.Take(i));
                    }

                    var newColumnExpression = BitBooleanExpression.Coerce(visitedColumnExpression);
                    var newColumnDeclaration = new SqlColumnDeclaration(column.Name, newColumnExpression);

                    newColumns.Add(newColumnDeclaration);
                }
                else if (visitedColumnExpression != column.Expression)
                {
                    if (newColumns == null)
                    {
                        newColumns = new List<SqlColumnDeclaration>(selectExpression.Columns.Take(i));
                    }

                    newColumns.Add(column.ReplaceExpression(visitedColumnExpression));
                }
                else if (newColumns != null)
                {
                    newColumns.Add(column);
                }
            }

            var where = this.Visit(selectExpression.Where);

            if ((where is BitBooleanExpression))
            {
                where = Expression.Equal(where, Expression.Constant(true));
            }

            if (where != selectExpression.Where)
            {
                if (newColumns != null)
                {
                    return selectExpression.ChangeWhereAndColumns(where, new ReadOnlyList<SqlColumnDeclaration>(newColumns));
                }
                else
                {
                    return selectExpression.ChangeWhere(where);
                }
            }
            else if (newColumns != null)
            {
                return selectExpression.ChangeColumns(newColumns, true);
            }
            else
            {
                return base.VisitSelect(selectExpression);
            }
        }