public override TSqlQuery Compile(ClauseCompilationContext context)
        {
            if (Value == null)
            {
                if (!NullValueComparisonOperators.Contains(Operation))
                {
                    throw new InvalidOperationException($"Invalid operation for null value. Should be one of {string.Join(", ", NullValueComparisonOperators)}");
                }
                return(GetNullValueQuery());
            }

            Dictionary <string, object> parameters = null;
            string valueString;

            if (Value is TSqlStatement tsqlStatement)
            {
                valueString = tsqlStatement.GetDescription();
            }
            else
            {
                string parameterName = SqlBuilderHelper.GetUniqueParameterName(SqlBuilderHelper.ComposeParameterName(Field.TableName, Field.FieldName), context);
                context.ParameterNames.Add(parameterName);

                parameters = new Dictionary <string, object> {
                    { parameterName, Value }
                };
                valueString = SqlBuilderHelper.PrepareParameterName(parameterName);
            }

            return(new TSqlQuery(
                       $"{Field.GetFullName()} {SqlBuilderHelper.ConvertBinaryOperationToString(Operation)} {valueString}",
                       parameters
                       ));
        }
Exemple #2
0
        public override TSqlQuery Compile(ClauseCompilationContext context)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append($"{JoinType.GetDescription()} {TSqlSyntax.Join} {SqlBuilderHelper.PrepareTableName(JoinedTable)}");
            if (TableHints.HasValue)
            {
                string hints = SqlBuilderHelper.GetTableHintString(TableHints.Value);
                sb.Append(" ");
                sb.Append($"{TSqlSyntax.With}({hints})");
            }
            sb.Append(" ");
            sb.Append($"{TSqlSyntax.On} {LeftField.GetFullName()} {SqlBuilderHelper.ConvertBinaryOperationToString(Operation)} {RightField.GetFullName()}");

            return(new TSqlQuery(sb.ToString()));
        }