Exemplo n.º 1
0
 public QueryEl Between(T lowerBound, T upperBound)
 {
     return(new QueryElOperator <T>(
                "({0} BETWEEN ({1}) AND ({2}))",
                this,
                QueryConversionHelper.ConvertParameter(lowerBound),
                QueryConversionHelper.ConvertParameter(upperBound)));
 }
Exemplo n.º 2
0
        public QueryEl In(IEnumerable <T> values)
        {
            var valuesList = values as ICollection <T>;

            if (valuesList == null && values != null)
            {
                valuesList = values.ToList();
            }

            if (valuesList == null ||
                valuesList.Count == 0)
            {
                // Always false
                return(new QueryElBool(false));
            }

            if (valuesList.Count == 1)
            {
                // If the SQL-Server knows there is only a single value, it does a much better job at optimizing the query
                // Do not generate an In-Statement in this case.
                return(new QueryElOperator <T>("({0}={1})", this, QueryConversionHelper.ConvertParameter(valuesList.Single())));
            }

            if (IdTypeExtension.IsIdType <T>() || IdTypeExtension.IsNullableIdType <T>())
            {
                var intsList = valuesList
                               .Where(v => v != null)
                               .Select(v => ((IConvertibleToInt32)v).ConvertToInt32())
                               // 2TK BDA initCapacity: valuesList.Count
                               .ToList();
                return(new QueryElSetOperator <int>("({0} IN (SELECT Value FROM {1}))", this, intsList));
            }

            if (LongIdTypeExtension.IsLongIdType <T>() || LongIdTypeExtension.IsNullableLongIdType <T>())
            {
                var longsList = valuesList
                                .Where(v => v != null)
                                .Select(v => ((IConvertibleToInt64)v).ConvertToInt64())
                                // 2TK BDA initCapacity: valuesList.Count
                                .ToList();
                return(new QueryElSetOperator <long>("({0} IN (SELECT Value FROM {1}))", this, longsList));
            }

            if (typeof(T) == typeof(string) || typeof(T) == typeof(int) || typeof(T) == typeof(int?))
            {
                return(new QueryElSetOperator <T>("({0} IN (SELECT Value FROM {1}))", this, valuesList));
            }

            var vals = valuesList.JoinString(",", onlyNonEmptyValues: true);

            if (string.IsNullOrEmpty(vals))
            {
                return(new QueryElBool(false));
            }

            return(new QueryElFormat("({0} IN ({1}))", this, vals));
        }
Exemplo n.º 3
0
 public static QueryElOperator <T> operator !=(QueryElOperator <T> x, T y)
 {
     return(y != null ? new QueryElOperator <T>("({0}<>{1})", x, QueryConversionHelper.ConvertParameter(y)) : new QueryElOperator <T>("({0} IS NULL)", x));
 }
 public static QueryElOperator <int> operator !=(QueryElMemberNullableId <TEntity> x, int y)
 {
     return(new QueryElOperator <int>("({0}<>{1})", x, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 5
0
 public static QueryElOperator <LongId <TEntity> > operator <=(QueryElMemberLongId <TEntity> x, long y)
 {
     return(new QueryElOperator <LongId <TEntity> >("({0}<={1})", x, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 6
0
 // Do not delete this operator. It is needed to evaluate ||.
 public static QueryEl operator |(QueryEl x, QueryEl y)
 {
     return(new QueryElOperator <bool>("(({0}) OR ({1}))", QueryConversionHelper.ConvertMember(x), QueryConversionHelper.ConvertMember(y)));
 }
Exemplo n.º 7
0
 public static QueryEl operator !(QueryEl x)
 {
     return(new QueryElOperator <bool>("(NOT {0})", QueryConversionHelper.ConvertMember(x)));
 }
Exemplo n.º 8
0
 public static QueryElOperator <T> operator >(QueryElMember <T> x, QueryElMember <T> y)
 {
     return(new QueryElOperator <T>("({0}>{1})", x, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 9
0
 public static QueryElOperator <T> operator >(QueryElMember <T> x, T y)
 {
     return(GetFalseQueryElOperatorOrNull(y) ?? new QueryElOperator <T>("({0}>{1})", x, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 10
0
 public QueryElOperator <T> NotEquals(QueryElOperator <T> y)
 {
     return(new QueryElOperator <T>("({0}<>{1})", this, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 11
0
 public static QueryElOperator <T> operator ==(QueryElMember <T> x, T y)
 {
     return(y != null ? new QueryElOperator <T>("({0}={1} AND {0} IS NOT NULL)", x, QueryConversionHelper.ConvertParameter(y)) : new QueryElOperator <T>("({0} IS NULL)", x));
 }
Exemplo n.º 12
0
 public static QueryElOperator <Id <TEntity> > operator <(QueryElMemberId <TEntity> x, int y)
 {
     return(new QueryElOperator <Id <TEntity> >("({0}<{1})", x, QueryConversionHelper.ConvertParameter(y)));
 }
Exemplo n.º 13
0
 public static QueryEl operator <=(QueryElMemberStruct <T> x, T?y)
 {
     return(y != null ? new QueryElOperator <T>("({0}<={1})", x, QueryConversionHelper.ConvertParameter(y)) : new QueryElOperator <T>("({0}<=NULL)", x));
 }