Ejemplo n.º 1
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.º 2
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));
            }
        }