Пример #1
0
        private static IEnumerable <IDbDataParameter> CreateParameters(IDbCommand command, ParameterTemplate parameterTemplate, object value)
        {
            var range = value as IRange;

            if (range != null)
            {
                yield return(CreateParameter(command, parameterTemplate, range.Start, "_start"));

                yield return(CreateParameter(command, parameterTemplate, range.End, "_end"));

                CommandBuilder.SetBetweenInCommandText(command, parameterTemplate.Name);
            }
            else
            {
                var list = value as IEnumerable;
                if (list != null)
                {
                    var builder = new StringBuilder();
                    var array   = list.Cast <object>().ToArray();
                    for (int i = 0; i < array.Length; i++)
                    {
                        builder.AppendFormat(",{0}_{1}", parameterTemplate.Name, i);
                        yield return(CreateParameter(command, parameterTemplate, array[i], "_" + i));
                    }
                    if (command.CommandText.Contains("!= " + parameterTemplate.Name))
                    {
                        command.CommandText = command.CommandText.Replace("!= " + parameterTemplate.Name,
                                                                          "NOT IN (" + builder.ToString().Substring(1) +
                                                                          ")");
                    }
                    else
                    {
                        command.CommandText = command.CommandText.Replace("= " + parameterTemplate.Name,
                                                                          "IN (" + builder.ToString().Substring(1) + ")");
                    }
                }
                else
                {
                    yield return(CreateParameter(command, parameterTemplate, value));
                }
            }
        }
Пример #2
0
        private IEnumerable <IDbDataParameter> CreateParameters(IDbCommand command, ParameterTemplate parameterTemplate, object value)
        {
            if (value == null || TypeHelper.IsKnownType(value.GetType()) || parameterTemplate.DbType == DbType.Binary)
            {
                yield return(CreateParameter(command, parameterTemplate, value));
            }
            else
            {
                var range = value as IRange;
                if (range != null)
                {
                    yield return(CreateParameter(command, parameterTemplate, range.Start, "_start"));

                    yield return(CreateParameter(command, parameterTemplate, range.End, "_end"));

                    CommandBuilder.SetBetweenInCommandText(command, parameterTemplate.Name);
                }
                else
                {
                    var list = value as IEnumerable;
                    if (list != null)
                    {
                        var builder = new StringBuilder();
                        var array   = list.Cast <object>().ToArray();
                        for (int i = 0; i < array.Length; i++)
                        {
                            builder.AppendFormat(",{0}_{1}", parameterTemplate.Name, i);
                            yield return(CreateParameter(command, parameterTemplate, array[i], "_" + i));
                        }
                        RewriteSqlEqualityToInClause(command, parameterTemplate, builder);
                    }
                    else
                    {
                        yield return(CreateParameter(command, parameterTemplate, value));
                    }
                }
            }
        }