Exemple #1
0
        internal void AddIntInRangeCause(string columnName, List <int> values)
        {
            if (values == null || values.Count == 0)
            {
                return;
            }

            if (values.Count == 1)
            {
                AddIntComparingCause(columnName, values[0]);
            }

            WhereCauseBuilder inner = new WhereCauseBuilder(parameters, false);

            for (int index = 0; index < values.Count; index++)
            {
                var parameterName = columnName + index.ToString();
                inner.AddIntComparingCause(columnName, values[index], parameterName);
            }
            whereCauses.Add("(" + inner.ToString() + ")");
        }
Exemple #2
0
 void AddStringComparingCause(string columnName, string value, StringPropertyComparingModes comparingModes, string parameterName, int length)
 {
     if (value != null)
     {
         if (value == "")
         {
             whereCauses.Add(string.Format("[{0}] = ''", columnName));
         }
         else
         {
             if (comparingModes == StringPropertyComparingModes.Contains)
             {
                 whereCauses.Add(string.Format("[{0}] like @{1}", columnName, parameterName));
                 parameters.Add(new SqlParameter("@" + parameterName, System.Data.SqlDbType.NVarChar, length * 3 + 2)
                 {
                     Value = SqlServerLikeValueBuilder.EscapeAndInclude(value)
                 });
             }
             else if (comparingModes == StringPropertyComparingModes.Equals)
             {
                 whereCauses.Add(string.Format("[{0}] = @{1}", columnName, parameterName));
                 parameters.Add(new SqlParameter("@" + parameterName, System.Data.SqlDbType.NVarChar, length * 3)
                 {
                     Value = SqlServerLikeValueBuilder.EscapeForEquals(value)
                 });
             }
             else if (comparingModes == StringPropertyComparingModes.StartsWith)
             {
                 whereCauses.Add(string.Format("[{0}] like @{1}", columnName, parameterName));
                 parameters.Add(new SqlParameter("@" + parameterName, System.Data.SqlDbType.NVarChar, length * 3 + 1)
                 {
                     Value = SqlServerLikeValueBuilder.Escape(value) + "%"
                 });
             }
             else if (comparingModes == StringPropertyComparingModes.EndsWith)
             {
                 whereCauses.Add(string.Format("[{0}] like @{1}", columnName, parameterName));
                 parameters.Add(new SqlParameter("@" + parameterName, System.Data.SqlDbType.NVarChar, length * 3 + 1)
                 {
                     Value = "%" + SqlServerLikeValueBuilder.Escape(value)
                 });
             }
             else
             {
                 WhereCauseBuilder inner = new WhereCauseBuilder(parameters, false);
                 if (comparingModes.HasFlag(StringPropertyComparingModes.Equals))
                 {
                     inner.AddStringComparingCause(columnName, value, StringPropertyComparingModes.Equals, "Equals" + columnName, length);
                 }
                 if (comparingModes.HasFlag(StringPropertyComparingModes.Contains))
                 {
                     inner.AddStringComparingCause(columnName, value, StringPropertyComparingModes.Contains, "Contains" + columnName, length);
                 }
                 if (comparingModes.HasFlag(StringPropertyComparingModes.StartsWith))
                 {
                     inner.AddStringComparingCause(columnName, value, StringPropertyComparingModes.StartsWith, "StartsWith" + columnName, length);
                 }
                 if (comparingModes.HasFlag(StringPropertyComparingModes.EndsWith))
                 {
                     inner.AddStringComparingCause(columnName, value, StringPropertyComparingModes.EndsWith, "EndsWith" + columnName, length);
                 }
                 whereCauses.Add("(" + inner.ToString() + ")");
             }
         }
     }
 }