/// <summary> /// Executes the rowmapper with a single input parameter. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="commandText">Store procedure name. E.g. "Posts_GetPostsByUser</param> /// <param name="commandType">StoredProcedure</param> /// <param name="rowMapper">The mapper that maps a record to an object.</param> /// <param name="paramName">E.g. "userName"</param> /// <param name="paramType">string</param> /// <param name="paramValue">user001</param> /// <returns></returns> public static IList <T> Query <T>(this IDBHelper dbHelper, string commandText, CommandType commandType, string paramName, DbType paramType, object paramValue, IRowMapper <IDataReader, T> rowMapper) { DbParameter parameter = dbHelper.BuildInParam(paramName, paramType, paramValue); return(Query <T>(dbHelper, commandText, commandType, new DbParameter[1] { parameter }, rowMapper)); }
/// <summary> /// Builds a command object with a single parameter. /// </summary> /// <param name="dbHelper"></param> /// <param name="commandText"></param> /// <param name="commandType"></param> /// <param name="paramName"></param> /// <param name="paramType"></param> /// <param name="paramValue"></param> /// <returns></returns> public static DbCommand BuildCommand(this IDBHelper dbHelper, string commandText, CommandType commandType, string paramName, DbType paramType, object paramValue) { DbConnection connection = dbHelper.GetConnection(); DbCommand command = dbHelper.GetCommand(connection, commandText, commandType); command.Connection = connection; command.Parameters.Add(dbHelper.BuildInParam(paramName, paramType, paramValue)); return(command); }
/// <summary> /// Execute a non-query with a single input parameter. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="commandText">E.g. Storedprocedure : Posts_DeleteByUser</param> /// <param name="commandType">Type of the command.</param> /// <param name="paramName">E.g. "@UserName"</param> /// <param name="paramType">E.g. DbType.String</param> /// <param name="paramValue">E.g. "kreddy"</param> /// <returns></returns> public static int Execute(this IDBHelper dbHelper, string commandText, CommandType commandType, string paramName, DbType paramType, object paramValue) { DbParameter parameter = dbHelper.BuildInParam(paramName, paramType, paramValue); return(dbHelper.ExecuteNonQuery(commandText, CommandType.StoredProcedure, parameter)); }