System.Data.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(System.Data.Common.CommandTrees.DbExpression)

Here are the examples of the csharp api class System.Data.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(System.Data.Common.CommandTrees.DbExpression) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

26 Examples 7

1. Example

Project: referencesource
Source File: ViewSimplifier.cs
View license
internal DbExpression CollapseProjection(DbExpression expression)
            {
                return this.VisitExpression(expression);
            }

2. Example

View license
internal static DbExpression RemoveParameterReferences(DbExpression expression, ObjectParameterCollection availableParameters)
            {
                ParameterReferenceRemover remover = new ParameterReferenceRemover(availableParameters);
                return remover.VisitExpression(expression);
            }

3. Example

View license
protected override DbExpression VisitExpression(DbExpression expression)
            {
                switch (expression.ExpressionKind)
                {
                    case DbExpressionKind.RelationshipNavigation:
                    case DbExpressionKind.Distinct:
                    case DbExpressionKind.Filter:
                    case DbExpressionKind.Limit:
                    case DbExpressionKind.OfType:
                    case DbExpressionKind.Project:
                    case DbExpressionKind.Sort:
                    case DbExpressionKind.Skip:
                        return base.VisitExpression(expression);

                    default:
                        return expression;
                }
            }

4. Example

View license
protected override DbExpression VisitExpression(DbExpression expression)
        {
            // Pre-process this visitor's rules
            DbExpression result = ApplyRules(expression);
            if (_stopped)
            {
                // If rule processing was stopped, the result expression must be returned immediately
                return result;
            }

            // Visit the expression to recursively apply rules to subexpressions
            result = base.VisitExpression(result);
            if (_stopped)
            {
                // If rule processing was stopped, the result expression must be returned immediately
                return result;
            }

            // Post-process the rules over the resulting expression and return the result.
            // This is done so that rules that did not match the original structure of the
            // expression have an opportunity to examine the structure of the result expression.
            result = ApplyRules(result);
            return result;
        }

5. Example

Project: referencesource
Source File: ExpressionCopier.cs
View license
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal static DbExpression BindToWorkspace(DbExpression expression, MetadataWorkspace targetWorkspace)
        {
            Debug.Assert(expression != null, "expression is null");

            DbExpressionRebinder copier = new DbExpressionRebinder(targetWorkspace);
            return copier.VisitExpression(expression);
        }

6. Example

Project: referencesource
Source File: ViewSimplifier.cs
View license
internal static DbExpression Substitute(DbExpression original, string referencedVariable, Dictionary<string, DbExpression> propertyValues)
            {
                Debug.Assert(original != null, "Original expression cannot be null");
                ValueSubstituter visitor = new ValueSubstituter(referencedVariable, propertyValues);
                return visitor.VisitExpression(original);
            }

7. Example

View license
private DbExpression VisitUnary(DbUnaryExpression expression, Func<DbExpression, DbExpression> callback)
        {
            DbExpression result = expression;
            DbExpression newArgument = this.VisitExpression(expression.Argument);
            if (!object.ReferenceEquals(expression.Argument, newArgument))
            {
                result = callback(newArgument);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

8. Example

View license
private DbExpression VisitBinary(DbBinaryExpression expression, Func<DbExpression, DbExpression, DbExpression> callback)
        {
            DbExpression result = expression;

            DbExpression newLeft = this.VisitExpression(expression.Left);
            DbExpression newRight = this.VisitExpression(expression.Right);
            if (!object.ReferenceEquals(expression.Left, newLeft) ||
                !object.ReferenceEquals(expression.Right, newRight))
            {
                result = callback(newLeft, newRight);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

9. Example

View license
private DbRelatedEntityRef VisitRelatedEntityRef(DbRelatedEntityRef entityRef)
        {
            RelationshipEndMember newSource; 
            RelationshipEndMember newTarget;
            VisitRelationshipEnds(entityRef.SourceEnd, entityRef.TargetEnd, out newSource, out newTarget);
            DbExpression newTargetRef = this.VisitExpression(entityRef.TargetEntityReference);

            if (!object.ReferenceEquals(entityRef.SourceEnd, newSource) ||
                !object.ReferenceEquals(entityRef.TargetEnd, newTarget) ||
                !object.ReferenceEquals(entityRef.TargetEntityReference, newTargetRef))
            {
                return CqtBuilder.CreateRelatedEntityRef(newSource, newTarget, newTargetRef);
            }
            else
            {
                return entityRef;
            }
        }

10. Example

View license
protected virtual DbExpressionBinding VisitExpressionBinding(DbExpressionBinding binding)
        {
            DbExpressionBinding result = binding;
            if (binding != null)
            {
                DbExpression newInput = this.VisitExpression(binding.Expression);
                if (!object.ReferenceEquals(binding.Expression, newInput))
                {
                    result = CqtBuilder.BindAs(newInput, binding.VariableName);
                    this.RebindVariable(binding.Variable, result.Variable);
                }
            }
            return result;
        }

11. Example

View license
protected virtual DbGroupExpressionBinding VisitGroupExpressionBinding(DbGroupExpressionBinding binding)
        {
            DbGroupExpressionBinding result = binding;
            if (binding != null)
            {
                DbExpression newInput = this.VisitExpression(binding.Expression);
                if (!object.ReferenceEquals(binding.Expression, newInput))
                {
                    result = CqtBuilder.GroupBindAs(newInput, binding.VariableName, binding.GroupVariableName);
                    this.RebindVariable(binding.Variable, result.Variable);
                    this.RebindVariable(binding.GroupVariable, result.GroupVariable);
                }
            }
            return result;
        }

12. Example

View license
private DbExpression VisitTypeUnary(DbUnaryExpression expression, TypeUsage type, Func<DbExpression, TypeUsage, DbExpression> callback)
        {
            DbExpression result = expression;

            DbExpression newArgument = this.VisitExpression(expression.Argument);
            TypeUsage newType = this.VisitTypeUsage(type);

            if (!object.ReferenceEquals(expression.Argument, newArgument) ||
                !object.ReferenceEquals(type, newType))
            {
                result = callback(newArgument, newType);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

13. Example

View license
public override DbExpression Visit(DbPropertyExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;
            DbExpression newInstance = this.VisitExpression(expression.Instance);
            if (!object.ReferenceEquals(expression.Instance, newInstance))
            {
                result = CqtBuilder.Property(newInstance, expression.Property.Name);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

14. Example

View license
public override DbExpression Visit(DbLikeExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpression newArgument = this.VisitExpression(expression.Argument);
            DbExpression newPattern = this.VisitExpression(expression.Pattern);
            DbExpression newEscape = this.VisitExpression(expression.Escape);

            if (!object.ReferenceEquals(expression.Argument, newArgument) ||
                !object.ReferenceEquals(expression.Pattern, newPattern) ||
                !object.ReferenceEquals(expression.Escape, newEscape))
            {
                result = CqtBuilder.Like(newArgument, newPattern, newEscape);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

15. Example

View license
public override DbExpression Visit(DbLimitExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpression newArgument = this.VisitExpression(expression.Argument);
            DbExpression newLimit = this.VisitExpression(expression.Limit);
            
            if (!object.ReferenceEquals(expression.Argument, newArgument) ||
                !object.ReferenceEquals(expression.Limit, newLimit))
            {
                Debug.Assert(!expression.WithTies, "Limit.WithTies == true?");
                result = CqtBuilder.Limit(newArgument, newLimit);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

16. Example

View license
public override DbExpression Visit(DbCaseExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            IList<DbExpression> newWhens = this.VisitExpressionList(expression.When);
            IList<DbExpression> newThens = this.VisitExpressionList(expression.Then);
            DbExpression newElse = this.VisitExpression(expression.Else);

            if (!object.ReferenceEquals(expression.When, newWhens) ||
                !object.ReferenceEquals(expression.Then, newThens) ||
                !object.ReferenceEquals(expression.Else, newElse))
            {
                result = CqtBuilder.Case(newWhens, newThens, newElse);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

17. Example

View license
public override DbExpression Visit(DbRelationshipNavigationExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            RelationshipEndMember newFrom;
            RelationshipEndMember newTo;
            VisitRelationshipEnds(expression.NavigateFrom, expression.NavigateTo, out newFrom, out newTo);
            DbExpression newNavSource = this.VisitExpression(expression.NavigationSource);

            if (!object.ReferenceEquals(expression.NavigateFrom, newFrom) ||
                !object.ReferenceEquals(expression.NavigateTo, newTo) ||
                !object.ReferenceEquals(expression.NavigationSource, newNavSource))
            {
                result = CqtBuilder.Navigate(newNavSource, newFrom, newTo);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

18. Example

View license
protected virtual DbSortClause VisitSortClause(DbSortClause clause)
        {
            DbSortClause result = clause;
            if (clause != null)
            {
                DbExpression newExpression = this.VisitExpression(clause.Expression);
                if (!object.ReferenceEquals(clause.Expression, newExpression))
                {
                    if (!string.IsNullOrEmpty(clause.Collation))
                    {
                        result = (clause.Ascending ? CqtBuilder.ToSortClause(newExpression, clause.Collation) : CqtBuilder.ToSortClauseDescending(newExpression, clause.Collation));
                    }
                    else
                    {
                        result = (clause.Ascending ? CqtBuilder.ToSortClause(newExpression) : CqtBuilder.ToSortClauseDescending(newExpression));
                    }
                }
            }
            return result;
        }

19. Example

View license
public override DbExpression Visit(DbRefExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            EntityType targetType = (EntityType)TypeHelpers.GetEdmType<RefType>(expression.ResultType).ElementType;

            DbExpression newArgument = this.VisitExpression(expression.Argument);
            EntityType newType = (EntityType)this.VisitType(targetType);
            EntitySet newSet = (EntitySet)this.VisitEntitySet(expression.EntitySet);
            if (!object.ReferenceEquals(expression.Argument, newArgument) ||
                !object.ReferenceEquals(targetType, newType) ||
                !object.ReferenceEquals(expression.EntitySet, newSet))
            {
                result = CqtBuilder.RefFromKey(newSet, newArgument, newType);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

20. Example

View license
public override DbExpression Visit(DbFilterExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpressionBinding input = this.VisitExpressionBindingEnterScope(expression.Input);
            DbExpression predicate = this.VisitExpression(expression.Predicate);
            this.ExitScope();
            if (!object.ReferenceEquals(expression.Input, input) ||
                !object.ReferenceEquals(expression.Predicate, predicate))
            {
                result = CqtBuilder.Filter(input, predicate);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

21. Example

View license
public override DbExpression Visit(DbProjectExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpressionBinding input = this.VisitExpressionBindingEnterScope(expression.Input);
            DbExpression projection = this.VisitExpression(expression.Projection);
            this.ExitScope();
            if (!object.ReferenceEquals(expression.Input, input) ||
                !object.ReferenceEquals(expression.Projection, projection))
            {
                result = CqtBuilder.Project(input, projection);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

22. Example

View license
public override DbExpression Visit(DbSkipExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpressionBinding newInput = this.VisitExpressionBindingEnterScope(expression.Input);
            IList<DbSortClause> newSortOrder = this.VisitSortOrder(expression.SortOrder);
            this.ExitScope();
            DbExpression newCount = this.VisitExpression(expression.Count);

            if (!object.ReferenceEquals(expression.Input, newInput) ||
                !object.ReferenceEquals(expression.SortOrder, newSortOrder) ||
                !object.ReferenceEquals(expression.Count, newCount))
            {
                result = CqtBuilder.Skip(newInput, newSortOrder, newCount);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

23. Example

Project: referencesource
Source File: ExpressionCopier.cs
View license
public override DbExpression Visit(DbPropertyExpression expression)
        {
            EntityUtil/n ..... /n //View Source file for more details /n }

24. Example

View license
protected virtual DbLambda VisitLambda(DbLambda lambda)
        {
            EntityUtil.CheckArgumentNull(lambda, "lambda");

            DbLambda result = lambda;
            IList<DbVariableReferenceExpression> newFormals = this.VisitList(lambda.Variables, varRef =>
                {
                    TypeUsage newVarType = this.VisitTypeUsage(varRef.ResultType);
                    if (!object.ReferenceEquals(varRef.ResultType, newVarType))
                    {
                        return CqtBuilder.Variable(newVarType, varRef.VariableName);
                    }
                    else
                    {
                        return varRef;
                    }
                }
            );
            this.EnterScope(newFormals.ToArray()); // ToArray: Don't pass the List instance directly to OnEnterScope
            DbExpression newBody = this.VisitExpression(lambda.Body);
            this.ExitScope();

            if (!object.ReferenceEquals(lambda.Variables, newFormals) ||
                !object.ReferenceEquals(lambda.Body, newBody))
            {
                result = CqtBuilder.Lambda(newBody, newFormals);
            }
            return result;
        }

25. Example

View license
public override DbExpression Visit(DbQuantifierExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            DbExpressionBinding input = this.VisitExpressionBindingEnterScope(expression.Input);
            DbExpression predicate = this.VisitExpression(expression.Predicate);
            this.ExitScope();

            if (!object.ReferenceEquals(expression.Input, input) ||
                !object.ReferenceEquals(expression.Predicate, predicate))
            {
                if (DbExpressionKind.All == expression.ExpressionKind)
                {
                    result = CqtBuilder.All(input, predicate);
                }
                else
                {
                    Debug.Assert(expression.ExpressionKind == DbExpressionKind.Any, "DbQuantifierExpression had ExpressionKind other than All or Any?");
                    result = CqtBuilder.Any(input, predicate);
                }
            }
            NotifyIfChanged(expression, result);
            return result;
        }

26. Example

View license
public override DbExpression Visit(DbJoinExpression expression)
        {
            EntityUtil.Che/n ..... /n //View Source file for more details /n }