public static IEnumerable <KeyValuePair <string, object> > RenderParamsAsKeyValuePairs(this SqlParameterCollection parameters)
        {
            var retval = parameters.Cast <SqlParameter>()
                         .Select(param => new KeyValuePair <string, object>(param.ParameterName, param.Value));

            return(retval);
        }
 public static string Dump(this SqlParameterCollection parameters)
 {
     return(parameters.Cast <SqlParameter>().Aggregate(
                new StringBuilder(),
                (acc, p) => acc.Append(p.ParameterName).Append(" = ").Append(p.Value).AppendLine(),
                acc => acc.ToString()));
 }
        /// <summary>
        /// Prepare executed SQL Command by replacing parameters with values - MS Sql
        /// </summary>
        /// <param name="command">Executed command</param>
        /// <param name="parameters">Command parameters</param>
        /// <returns>SQL Command</returns>
        public static string PrepareSql(SqlCommand command, SqlParameterCollection parameters)
        {
            string res = command.CommandText;

            if (command.CommandType == CommandType.StoredProcedure)
            {
                var strParams = (from SqlParameter parameter in parameters select $"{parameter.ParameterName} = {parameter.Value}").ToList();
                return($"{res} {string.Join(", ", strParams)}");
            }

            return(parameters.Cast <SqlParameter>().Aggregate(res, (current, parameter) => current.Replace($"@{parameter.ParameterName}", parameter.Value.ToString())));
        }
        /// <summary>
        /// 将Request里的参数转成SqlParameter[]
        /// </summary>
        /// <returns></returns>
        internal static void RequestParasToSqlParameters(SqlParameterCollection oldParas)
        {
            var oldParaList      = oldParas.Cast <SqlParameter>().ToList();
            var paraDictionarAll = SqlSugarTool.GetParameterDictionary();

            if (paraDictionarAll != null && paraDictionarAll.Count() > 0)
            {
                foreach (KeyValuePair <string, string> it in paraDictionarAll)
                {
                    var par = new SqlParameter("@" + it.Key, it.Value);
                    if (!oldParaList.Any(oldPara => oldPara.ParameterName == ("@" + it.Key)))
                    {
                        oldParas.Add(par);
                    }
                }
            }
        }
Beispiel #5
0
        string ParameterInfo(SqlParameterCollection sqlParameterCollection)
        {
            var parameterInfoBuilder = new StringBuilder();

            parameterInfoBuilder.Append(GenericConstants.CHR_SPACE);
            parameterInfoBuilder.Append(GenericConstants.BRACKET_CURLYOPEN);
            parameterInfoBuilder.Append(GenericConstants.CHR_SPACE);

            foreach (var sqlParameter in sqlParameterCollection.Cast <SqlParameter>().ToList())
            {
                parameterInfoBuilder.Append(GenericConstants.LOG_PARAMETERNAME);
                parameterInfoBuilder.Append(GenericConstants.CHR_SPACE);
                parameterInfoBuilder.Append(sqlParameter.ParameterName);
                parameterInfoBuilder.Append(GenericConstants.CHR_COMMA);
                parameterInfoBuilder.Append(GenericConstants.LOG_PARAMETERVALUE);
                parameterInfoBuilder.Append(sqlParameter.SqlValue);
                parameterInfoBuilder.Append(GenericConstants.CHR_SPACE);
            }

            parameterInfoBuilder.Append(GenericConstants.CHR_SPACE);
            parameterInfoBuilder.Append(GenericConstants.BRACKET_CURLYCLOSED);

            return(parameterInfoBuilder.ToString());
        }
Beispiel #6
0
 public static SqlParameter FindByName(this SqlParameterCollection collection, string name)
 {
     return(collection.Cast <SqlParameter>().Single(p => p.ParameterName == name));
 }
Beispiel #7
0
 public static T Get <T>(string query, SqlParameterCollection parameter) where T : new()
 {
     return(Get <T>(query, string.Empty, parameter.Cast <SqlParameter>().ToArray()));
 }
Beispiel #8
0
 private static Dictionary <string, object> BuildParameterDictionary(SqlParameterCollection parameters)
 {
     return(parameters.Cast <SqlParameter>()
            .Where(parameter => parameter.Direction == ParameterDirection.Output || parameter.Direction == ParameterDirection.InputOutput)
            .ToDictionary(parameter => parameter.ParameterName, parameter => parameter.Value));
 }