示例#1
0
            /// <summary>
            /// Will be called when the expression is a binary expression. E.g. Id == "value" or Id.CompareTo("value") > 0
            /// </summary>
            /// <param name="node"></param>
            /// <returns></returns>
            protected override Expression VisitBinary(BinaryExpression node)
            {
                MemberExpression propertyExpression = null;

                //E.g. Id.CompareTo("value") > 0
                if (node.Left is MethodCallExpression methodCallExpression)
                {
                    propertyExpression = methodCallExpression.Object as MemberExpression;
                }
                //E.g. Id == "value"
                else if (node.Left is MemberExpression)
                {
                    propertyExpression = node.Left as MemberExpression;
                }

                //Checks if the member of the expression is the field 'Id'
                if (propertyExpression?.Member?.Name == "Id")
                {
                    //Pass the expression the IdValueUpdateVisitor to add the table prefix to the expression constant
                    var visitor = new IdValueUpdateVisitor();
                    node = visitor.Visit(node) as BinaryExpression;
                }

                return(base.VisitBinary(node));
            }
示例#2
0
            /// <summary>
            /// Will be called when the expression is a method call (A method that returns a boolean in our particular case)
            /// E.g. Id.StartsWith("value") or Id.Contains("value")
            /// </summary>
            /// <param name="node"></param>
            /// <returns></returns>
            protected override Expression VisitMethodCall(MethodCallExpression node)
            {
                //We only want to modify the expression value if the method is 'StartsWith',
                //because the entities in the collection are all prefixed with the table name
                if (node.Method.Name == "StartsWith")
                {
                    var visitor = new IdValueUpdateVisitor();
                    node = visitor.Visit(node) as MethodCallExpression;
                }

                return(base.VisitMethodCall(node));
            }