Beispiel #1
0
        public override string GetSql(SqlParameterCollection parameters, int joinCount)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (typeof(T) == typeof(int))
            {
                string paramName = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramName, SqlParameterUtils.Create(paramName, values.OfType <int>()));
                stringBuilder.Append(paramName);
            }
            else if (typeof(T) == typeof(int?))
            {
                string paramName = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramName, SqlParameterUtils.Create(paramName, values.OfType <int?>()));
                stringBuilder.Append(paramName);
            }
            else if (typeof(T) == typeof(long))
            {
                string paramName = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramName, SqlParameterUtils.Create(paramName, values.OfType <long>()));
                stringBuilder.Append(paramName);
            }
            else if (typeof(T) == typeof(long?))
            {
                string paramName = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramName, SqlParameterUtils.Create(paramName, values.OfType <long?>()));
                stringBuilder.Append(paramName);
            }
            else if (typeof(T) == typeof(string))
            {
                string paramName = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramName, SqlParameterUtils.Create(paramName, values.OfType <string>()));
                stringBuilder.Append(paramName);
            }
            else
            {
                int i = 0;
                foreach (T value in values)
                {
                    if (!value.Equals(default(T)))
                    {
                        if (i > 0)
                        {
                            stringBuilder.Append(", ");
                        }

                        string paramName = "@" + parameters.Count;
                        stringBuilder.Append(paramName);
                        QueryHelpers.AddSqlParameter(parameters, paramName, value);
                        i++;
                    }
                }
            }

            string str1 = queryEls[0].GetSql(parameters, joinCount);

            return(string.Format(sql, str1, stringBuilder));
        }
Beispiel #2
0
        public override string GetSql(SqlParameterCollection parameters, int joinCount)
        {
            string[] paramStrings = new string[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                paramStrings[i] = "@" + parameters.Count;
                QueryHelpers.AddSqlParameter(parameters, paramStrings[i], values[i]);
            }

            return(string.Format(sql, paramStrings));
        }
Beispiel #3
0
        public override string GetSql(SqlParameterCollection parameters, int joinCount)
        {
            var booleanValue = value as bool?;

            if (booleanValue != null)
            {
                // To help the query optimizer to create separate query plans for the true and false case we hard code boolean values
                return(booleanValue.Value ? "1" : "0");
            }

            int?   intValue;
            object sqlValue;

            if (value == null)
            {
                intValue = null;
                sqlValue = null;
            }
            else if (value is IConvertibleToInt32)
            {
                intValue = ((IConvertibleToInt32)value).ConvertToInt32();
                sqlValue = intValue;
            }
            else
            {
                intValue = value as int?;
                sqlValue = value;
            }

            if (intValue == 406802) // DbEntityIds.MandatorIds.Galaxus
            {
                // Since we had problems with queries for the mandator Galaxus (which typically returns a lot more rows that queries for other customers),
                // we hard code the mandatorId to let the query optimizer create a separate query plan for the mandator galaxus
                return(intValue.Value.ToString());
            }

            string rawSql = "@" + parameters.Count;

            QueryHelpers.AddSqlParameter(parameters, rawSql, sqlValue);
            return(rawSql);
        }