public async Task <DataSet> GetDataSetAsync(SqlDataAccessHelper helper) { var reader = await GetDataReaderAsync(helper); var ds = new DataSet(); while (!reader.IsClosed) { var dt = new DataTable(); dt.Load(reader); ds.Tables.Add(dt); } ; return(ds); }
public async Task <IList <T> > FillAsync <T>(SqlDataAccessHelper helper) { var returnList = new List <T>(); var accessTimer = new Stopwatch(); var mappingTimer = new Stopwatch(); try { // ReSharper disable once SwitchStatementMissingSomeCases switch (helper.ExecutionContext.DataRetrievalType) { case DataActionRetrievalType.DataSet: accessTimer.Start(); var ds = await GetDataSetAsync(helper); accessTimer.Stop(); MassageResults(ref helper, ref ds, ref returnList, ref accessTimer, ref mappingTimer); break; case DataActionRetrievalType.DataReader: accessTimer.Start(); var dr = GetDataReaderAsync(helper); accessTimer.Stop(); MassageResults(ref helper, dr.Result, ref returnList, ref accessTimer, ref mappingTimer); break; } return(returnList); } catch (Exception e) { helper.ExecutionContext.ExecutionEvent.ExecutionErrors.Add(e); throw; } }
private SqlCommand GetCommand(SqlDataAccessHelper helper) { var sqlCommand = Connection.CreateCommand(); sqlCommand.CommandTimeout = helper.ExecutionContext.Timeout; if (UnitOfWork != null && UnitOfWork.CurrentlyOpen) { sqlCommand.Transaction = UnitOfWork.GetSqlTransaction(Connection.ConnectionString); } sqlCommand.CommandType = CommandType.Text; switch (helper.ExecutionContext.ActionType) { case DataAccessActionType.Statement: sqlCommand.CommandText = helper.ExecutionContext.Statement; break; case DataAccessActionType.Procedure: sqlCommand.CommandText = helper.ExecutionContext.ProcedureName; sqlCommand.CommandType = CommandType.StoredProcedure; break; } foreach (var parameter in helper.ExecutionContext.ParameterMappings.Values) { sqlCommand.Parameters.Add( new SqlParameter { ParameterName = parameter.Name, Value = parameter.Value ?? DBNull.Value, SqlDbType = parameter.DataType }); } return(sqlCommand); }
public DataSet GetDataSet(SqlDataAccessHelper helper) { var ds = new DataSet(); var sqlCommand = GetCommand(helper); SqlDataAdapter sqlDa = null; try { sqlDa = new SqlDataAdapter(sqlCommand); PrepareConnection(); sqlDa.Fill(ds); } finally { FinalizeConnection(); sqlDa?.Dispose(); } return(ds); }
public async Task <T> GetAsync <T>(SqlDataAccessHelper helper) { var returnList = await FillAsync <T>(helper); return(returnList.Count == 0 ? default(T) : returnList[0]); }
public T Get <T>(SqlDataAccessHelper helper) { var returnList = Fill <T>(helper); return(returnList.Count == 0 ? default(T) : returnList[0]); }
public async Task <int> ExecuteAsync(SqlDataAccessHelper helper) { return(await GetAsync <int>(helper)); }
public int Execute(SqlDataAccessHelper helper) { return(Get <int>(helper)); }
public async Task <IDictionary <TKey, TObjType> > FillToDictionaryAsync <TKey, TObjType>(string keyPropertyName, SqlDataAccessHelper helper, bool overwriteOnDupe = false) { var initialReturn = await FillAsync <TObjType>(helper); var returnList = SqlMapper.KeyedMap <TKey, TObjType>(keyPropertyName, initialReturn, helper.ExecutionContext, false); return(returnList); }