//public DbManager() // : base(DB_Tiny_URL.GetConnectionId()) //{ //} public static IEnumerable <TResult> Query <TResult>(string queryName, DbQueryOption queryOption) { using (var sqlConnection = new SqlConnection(queryOption.ConnectionID)) { try { if (sqlConnection.State != ConnectionState.Open) { sqlConnection.Open(); } return((IEnumerable <TResult>)sqlConnection.Query <TResult>(queryName, queryOption.ParameterModel, commandType: CommandType.StoredProcedure)); } catch (Exception) { throw; } //finally { // sqlConnection.Close(); //} } }
//public static TResult QuerySingle<TResult>(string queryName, DbQueryOption queryOption) //{ // using (var sqlConnection = new SqlConnection(queryOption.ConnectionID)) { // try { // if (sqlConnection.State != ConnectionState.Open) { // sqlConnection.Open(); // } // return (TResult)sqlConnection.QuerySingle<TResult>(queryName, queryOption.ParameterModel, commandType: CommandType.StoredProcedure); // } // catch (Exception) { // throw; // } // //finally { // // sqlConnection.Close(); // //} // } //} public static async Task <TResult> QuerySingleAsync <TResult>(string queryName, DbQueryOption queryOption) { using (var sqlConnection = new System.Data.SqlClient.SqlConnection(queryOption.ConnectionID)) { try { if (sqlConnection.State != ConnectionState.Open) { await sqlConnection.OpenAsync(); } return(await(Task <TResult>) sqlConnection.QuerySingleAsync <TResult>(queryName, queryOption.ParameterModel, commandType: CommandType.StoredProcedure)); } catch (Exception) { throw; } //finally { // sqlConnection.Close(); //} } }