Example #1
0
        /// <summary>
        /// Creates a Sql In clause for filters
        /// </summary>
        /// <typeparam name="listType">
        /// Type of the items in the list of values
        /// </typeparam>
        /// <param name="valuesList">
        /// List of values for create the In sentence
        /// </param>
        /// <returns>
        /// Sql In clause for filters
        /// </returns>
        protected virtual Command InClause(List <IComparable> valuesList)
        {
            //Initializing In clause
            Command command = new Command();

            command.Script = " IN (";
            string randomPrefix = new Random().Next(0, 999999).ToString();

            //Crossing the elements of the list
            for (int i = 0; i < valuesList.Count; i++)
            {
                IComparable item      = valuesList[i];
                string      paramName = randomPrefix + "_" + i;

                command.Script += paramName + ", ";
                command.Parameters.Add(new CommandParameter()
                {
                    Name = paramName, DbType = DbTypeMapper.Parse(item.GetType()), Value = item
                });
            }

            //Removing last ", "
            command.Script = command.Script.TrimEnd(',', ' ');

            //Closing the clause
            command.Script += ")";

            //Returning the filter
            return(command);
        }
Example #2
0
        public CommandParameter(object value, string name)
        {
            Name  = name;
            Value = value;

            if (string.IsNullOrWhiteSpace(name))
            {
                CreateRandomName();
            }
            else
            {
                Name = name;
            }

            if (value != null)
            {
                DbType = DbTypeMapper.Parse(value.GetType());
            }
        }
Example #3
0
 protected CommandParameter CreateCommandParameter(object value)
 {
     return(CreateCommandParameter(value, DbTypeMapper.Parse(value.GetType())));
 }