Example #1
0
        public SqlHelper GenerateSql(SqlHelper builder)
        {
            // Exit if it is empty
            if (IsEmpty()) return builder;

            if (FieldValue != null)
            {
                builder.Add(FieldName, FieldValue);
            }
            if (FieldValueFrom != null && FieldValueTo != null)
            {
                builder.BETWEEN(FieldName, FieldValueFrom, FieldValueTo);
            }
            if (!string.IsNullOrEmpty(FieldValueLike))
            {
                builder.LIKE(FieldName, FieldValueLike, FullTextSearch);
            }
            if (GreaterThanValue != null)
            {
                builder.Add(FieldName, ">", GreaterThanValue);
            }
            if (LessThanValue != null)
            {
                builder.Add(FieldName, "<", LessThanValue);
            }
            if (GreaterThanOrEqualToValue != null)
            {
                builder.Add(FieldName, ">=", GreaterThanOrEqualToValue);
            }
            if (LessThanOrEqualToValue != null)
            {
                builder.Add(FieldName, "<=", LessThanOrEqualToValue);
            }
            if (_IsNull.HasValue)
            {
                builder.Add(FieldName + (_IsNull.Value ? " IS NULL" : " IS NOT NULL"));
            }
            if (NotEqualToValue != null)
            {
                builder.Add(FieldName, "!=", NotEqualToValue);
            }
            if (InValues != null)
            {
                builder.IN(FieldName, InValues);
            }
            if (!string.IsNullOrEmpty(StartsWithValue))
            {
                builder.StartsWith(FieldName, StartsWithValue);
            }
            if (!string.IsNullOrEmpty(EndsWithValue))
            {
                builder.EndsWith(FieldName, EndsWithValue);
            }
            return builder;
        }