Ejemplo n.º 1
0
 /// <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 = '@')
 {
     using (var exec = new DbExecutor(connection, parameterSymbol))
     {
         return(exec.Delete(tableName, whereCondition));
     }
 }
Ejemplo n.º 2
0
 /// <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 = '@')
 {
     using (var exec = new DbExecutor(connection, parameterSymbol))
     {
         return(exec.Insert(tableName, insertItem));
     }
 }
Ejemplo n.º 3
0
 /// <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)
 {
     using (var exec = new DbExecutor(connection))
     {
         return(exec.ExecuteScalar <T>(query, parameter, commandType));
     }
 }
Ejemplo n.º 4
0
 static IEnumerable <IDataRecord> ExecuteReaderHelper(IDbConnection connection, string query, object parameter, CommandType commandType, CommandBehavior commandBehavior)
 {
     using (var exec = new DbExecutor(connection))
     {
         foreach (var item in exec.ExecuteReader(query, parameter, commandType, commandBehavior))
         {
             yield return(item);
         }
     }
 }
Ejemplo n.º 5
0
 static IEnumerable <dynamic> SelectDynamicHelper(IDbConnection connection, string query, object parameter, CommandType commandType)
 {
     using (var exec = new DbExecutor(connection))
     {
         foreach (var item in exec.SelectDynamic(query, parameter, commandType))
         {
             yield return(item);
         }
     }
 }
Ejemplo n.º 6
0
        /// <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));
            }
        }
Ejemplo n.º 7
0
        /// <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));
            }
        }
Ejemplo n.º 8
0
        /// <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));
            }
        }
Ejemplo n.º 9
0
 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);
         }
     }
 }