static IEnumerable <dynamic> ExecuteReaderDynamicHelper(IDbConnection connection, string query, object parameter, CommandType commandType, CommandBehavior commandBehavior) { using (var exec = new DbExecutor(connection)) { foreach (var item in exec.ExecuteReaderDynamic(query, parameter, commandType, commandBehavior)) { yield return(item); } } }
/// <summary>Executes and returns the first column, first row.<para>When done dispose connection.</para></summary> /// <param name="connection">Database connection.</param> /// <typeparam name="T">Result type.</typeparam> /// <param name="query">SQL code.</param> /// <param name="parameter">PropertyName parameterized to PropertyName. if null then no use parameter.</param> /// <param name="commandType">Command Type.</param> /// <returns>Query results of first column, first row.</returns> public static T ExecuteScalar <T>(IDbConnection connection, string query, object parameter = null, CommandType commandType = CommandType.Text) { Contract.Requires <ArgumentNullException>(connection != null); Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(query)); using (var exec = new DbExecutor(connection)) { return(exec.ExecuteScalar <T>(query, parameter, commandType)); } }
/// <summary>Delete by object's PropertyName.<para>When done dispose connection.</para></summary> /// <param name="connection">Database connection.</param> /// <param name="tableName">Target database's table.</param> /// <param name="whereCondition">Where condition extracted from PropertyName.</param> /// <param name="parameterSymbol">Command parameter symbol. SqlServer = '@', MySql = '?', Oracle = ':'</param> /// <returns>Rows affected.</returns> public static int Delete(IDbConnection connection, string tableName, object whereCondition, char parameterSymbol = '@') { Contract.Requires <ArgumentNullException>(connection != null); Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(tableName)); Contract.Requires <ArgumentNullException>(whereCondition != null); using (var exec = new DbExecutor(connection, parameterSymbol)) { return(exec.Delete(tableName, whereCondition)); } }
/// <summary>Insert by object's PropertyName.<para>When done dispose connection.</para></summary> /// <param name="connection">Database connection.</param> /// <param name="tableName">Target database's table.</param> /// <param name="insertItem">Table's column name extracted from PropertyName.</param> /// <param name="parameterSymbol">Command parameter symbol. SqlServer = '@', MySql = '?', Oracle = ':'</param> /// <returns>Rows affected.</returns> public static int Insert(IDbConnection connection, string tableName, object insertItem, char parameterSymbol = '@') { Contract.Requires <ArgumentNullException>(connection != null); Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(tableName)); Contract.Requires <ArgumentNullException>(insertItem != null); using (var exec = new DbExecutor(connection, parameterSymbol)) { return(exec.Insert(tableName, insertItem)); } }
static IEnumerable <T> SelectHelper <T>(IDbConnection connection, string query, object parameter, CommandType commandType) where T : new() { using (var exec = new DbExecutor(connection)) { foreach (var item in exec.Select <T>(query, parameter, commandType)) { yield return(item); } } }
public static DataTable GetTable(DbProviderFactory factory, string connectionString, string sqlQuery, object parameter = null, CommandType commandType = CommandType.Text) { #region Validation Contract.Requires <ArgumentNullException>(factory != null); Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(sqlQuery)); Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(connectionString)); #endregion var conn = factory.CreateConnection(); conn.ConnectionString = connectionString; Contract.Assume(conn != null); using (var exec = new DbExecutor(conn)) { return(exec.GetTable(factory, sqlQuery, parameter, commandType)); } }