コード例 #1
0
        protected virtual void VisitStringLiteralExpression(StringBuilder sb, BinaryStringOperator binaryStringOperator,
                                                            LiteralExpression <string> expression)
        {
            if (string.IsNullOrEmpty(expression.Value))
            {
                sb.Append(" NULL ");
                return;
            }

            string v;

            switch (binaryStringOperator)
            {
            case BinaryStringOperator.StartsWith:
                v = expression.Value + "%";
                break;

            case BinaryStringOperator.EndsWith:
                v = "%" + expression.Value;
                break;

            case BinaryStringOperator.Contains:
                v = "%" + expression.Value + "%";
                break;

            case BinaryStringOperator.Equals:
            case BinaryStringOperator.NotEquals:
            default:
                v = expression.Value;
                break;
            }

            sb.Append(CreateParameter(v).ParameterName);
        }
コード例 #2
0
        protected virtual string GetBinaryStringExpressionString(BinaryStringOperator binaryStringOperator,
                                                                 Expression right)
        {
            if (right is LiteralExpression &&
                (Equals(null, ((LiteralExpression)right).Value) ||
                 Equals(string.Empty, ((LiteralExpression)right).Value)))
            {
                switch (binaryStringOperator)
                {
                case BinaryStringOperator.Equals:
                    return(" IS ");

                case BinaryStringOperator.NotEquals:
                    return(" IS NOT ");

                case BinaryStringOperator.Contains:
                case BinaryStringOperator.EndsWith:
                case BinaryStringOperator.StartsWith:
                default:
                    break;
                }
            }

            switch (binaryStringOperator)
            {
            case BinaryStringOperator.Equals:
                return(" = ");

            case BinaryStringOperator.NotEquals:
                return(" <> ");

            case BinaryStringOperator.Contains:
            case BinaryStringOperator.EndsWith:
            case BinaryStringOperator.StartsWith:
            default:
                return(" LIKE ");
            }
        }