// Supressing this as we pass sprocname from constant at all times public static List <T> GetEntityCollection <T>(this RepositoryBase <T> repository, T entity, string sprocName) { try { Stopwatch sw = Stopwatch.StartNew(); IDbCommand command; if (entity != null) { command = new SqlCommand().GetCommandWithParameters(entity, sprocName); } else { command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = sprocName; } command.CommandTimeout = 240; SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; List <T> entities = (List <T>)EntityMapper.MapCollection <T>(command.ExecuteReader()); DBConnectionHelper.CloseSqlConnection(conn); sw.Stop(); return(entities); } catch (SqlException ex) { throw; } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="sprocParametersList"></param> /// <param name="sprocName"></param> /// <returns></returns> public static List <T> GetEntityCollection <T>(this RepositoryBase <T> repository, Dictionary <string, object> sprocParametersList, string sprocName) { try { Stopwatch sw = Stopwatch.StartNew(); IDbCommand command = new SqlCommand().GetCommandWithParameters(sprocParametersList, sprocName); SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; List <T> entities = (List <T>)EntityMapper.MapCollection <T>(command.ExecuteReader()); DBConnectionHelper.CloseSqlConnection(conn); sw.Stop(); return(entities); } catch (SqlException ex) { throw; } }
public static T GetEntity <T>(this RepositoryBase <T> repository, T entity, string sprocName) { try { Stopwatch sw = Stopwatch.StartNew(); IDbCommand command = new SqlCommand().GetCommandWithParameters(entity, sprocName); SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; entity = EntityMapper.MapSingle <T>(command.ExecuteReader()); DBConnectionHelper.CloseSqlConnection(conn); sw.Stop(); } catch (SqlException ex) { repository.ValidationErrors.Add("APPLICATION_WARNING_MESSAGE", ex.Message, false); entity = default(T); } return(entity); }
public static DataSet GetEntityDataSet <T1>(this RepositoryBase <T1> repository, Dictionary <string, object> sprocParametersList, string sprocName) { try { Stopwatch sw = Stopwatch.StartNew(); DataSet dataSet = new DataSet(); SqlDataAdapter dataAdapter = new SqlDataAdapter(); IDbCommand command = new SqlCommand().GetCommandWithParameters(sprocParametersList, sprocName); SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; dataAdapter.SelectCommand = (SqlCommand)command; dataAdapter.Fill(dataSet); DBConnectionHelper.CloseSqlConnection(conn); return(dataSet); } catch (SqlException ex) { throw; } }
public static bool InsertOrUpdate <T>(this RepositoryBase <T> repository, Dictionary <string, object> dictionary, string sprocName) { int isSuccess; try { Stopwatch sw = Stopwatch.StartNew(); IDbCommand command = new SqlCommand().GetCommandWithParameters(dictionary, sprocName); SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; isSuccess = command.ExecuteNonQuery(); DBConnectionHelper.CloseSqlConnection(conn); sw.Stop(); return(isSuccess > 0); } catch (SqlException ex) { throw; } }
public static int InsertAndGetEntityID <T>(this RepositoryBase <T> repository, T entity, string sprocName) { int entityID; try { Stopwatch sw = Stopwatch.StartNew(); IDbCommand command = new SqlCommand().GetCommandWithParameters(entity, sprocName); SqlConnection conn = DBConnectionHelper.OpenNewSqlConnection(repository.ConnectionString); command.Connection = conn; entityID = Convert.ToInt32(command.ExecuteScalar()); DBConnectionHelper.CloseSqlConnection(conn); sw.Stop(); } catch (SqlException ex) { throw; } return(entityID); }