Beispiel #1
0
        /// <summary>
        /// Query the database to get a single value
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="EstablishedConnection">An open and established connection to a MySQL database</param>
        /// <param name="QueryString">SQL query to retrieve the value requested</param>
        /// <param name="Parameters">Dictionary of named parameters</param>
        /// <param name="ThrowException">Throw exception or swallow and return default(T)</param>
        /// <returns>Single value of type T</returns>
        internal static T GetScalar <T>(MySqlConnection EstablishedConnection, string QueryString, Dictionary <string, object> Parameters = null, bool ThrowException = true, MySqlTransaction SqlTransaction = null)
        {
            return(DatabaseWorkHelper.DoDatabaseWork <T>(EstablishedConnection, QueryString,
                                                         (cmd) =>
            {
                cmd.Parameters.AddAllParameters(Parameters);

                var scalarResult = cmd.ExecuteScalar();

                return DatabaseCoreUtilities.ConvertScalar <T>(scalarResult);
            },
                                                         ThrowException: ThrowException, UseTransaction: SqlTransaction != null, SqlTransaction: SqlTransaction));
        }
Beispiel #2
0
 internal static IEnumerable <T> GetDataList <T>(MySqlConnection ExistingConnection, string QueryString, Dictionary <string, object> Parameters = null, bool ThrowException = true, MySqlTransaction SqlTransaction = null)      //where T : DALBaseModel
 {
     return(RefinedResultsHelper.GetDataTable(ExistingConnection, QueryString, Parameters: Parameters, ThrowException: ThrowException, SqlTransaction: SqlTransaction)
            .AsEnumerable()
            .Select(x => (T)DatabaseCoreUtilities.ConvertScalar <T>(x[0])));
 }