コード例 #1
0
        /// <summary>
        /// Add parameters to a given command.
        /// </summary>
        /// <param name="cmd">The command to add parameters to.</param>
        /// <param name="parameters">The object containing parameters to add.</param>
        public static void AddParameters(this IDbCommand cmd, object parameters = null)
        {
            // fill in a null parameter with empty parameter
            if (parameters == null)
            {
                parameters = Parameters.Empty;
            }

            DbParameterGenerator.GetInputParameterGenerator(cmd, parameters.GetType())(cmd, parameters);

            InsightDbProvider.For(cmd).FixupCommand(cmd);
        }
コード例 #2
0
        /// <summary>
        /// 获取参数生成器
        /// </summary>
        /// <param name="dataProvider">数据提供程序</param>
        DbParameterGenerator GetParameterGenerator(DataProvider dataProvider)
        {
            DbParameterGenerator parameterGenerator = null;

            switch (dataProvider)
            {
            case DataProvider.SQLServer:
            case DataProvider.Oracle:
            //parameterGenerator = new OracleParameterGenerator();
            case DataProvider.OleDB:
            case DataProvider.ODBC:
            case DataProvider.None:
            default:
                throw new NotImplementedException();
            }
            return(parameterGenerator);
        }
コード例 #3
0
        /// <summary>
        /// Takes the output parameters of a result set and inserts them into the result object.
        /// </summary>
        /// <typeparam name="T">The type of object to return.</typeparam>
        /// <param name="command">The command to evaluate.</param>
        /// <param name="result">The result to insert into.</param>
        /// <returns>The object that was filled in.</returns>
        public static T OutputParameters <T>(this IDbCommand command, T result)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // if there is no output object, don't attempt to fill it in
            if (result == null)
            {
                return(result);
            }

            InsightDbProvider.For(command).FixupOutputParameters(command);

            if (result is DynamicObject)
            {
                // handle dynamic objects by assigning their properties right into the dictionary
                IDictionary <string, object> dictionary = result as IDictionary <string, object>;
                if (dictionary == null)
                {
                    throw new InvalidOperationException("Dynamic object must support IDictionary<string, object>.");
                }

                foreach (IDataParameter p in command.Parameters)
                {
                    if (p.Direction.HasFlag(ParameterDirection.Output))
                    {
                        dictionary[p.ParameterName] = p.Value;
                    }
                }
            }
            else
            {
                DbParameterGenerator.GetOutputParameterConverter(command, result.GetType())(command, result);
            }

            return(result);
        }