public virtual List <T> Read <T>(T entity) where T : new() { DoubleASqlMapper mapData = new DoubleASqlMapper(); List <T> entityList = null; IDataReader reader = null; try { SqlCommand command = base.Read <T>(entity); OpenConnection(command, this.Connection); reader = command.ExecuteReader(); entityList = mapData.MapDataToListWithAttributes <T>(reader); } catch (Exception ex) { throw ex; } finally { if (reader != null) { reader.Close(); } } return(entityList); }
public virtual T1 ReadWithDetails <T1, T2>(T1 entity) where T1 : new() where T2 : new() { DoubleASqlMapper mapData = new DoubleASqlMapper(); T1 outEntity; IDataReader reader = null; try { SqlCommand command = base.Read <T1>(entity); OpenConnection(command, this.Connection); reader = command.ExecuteReader(); outEntity = mapData.MapDataToEntityWithDetailsWithAttributes <T1, T2>(reader); } catch (Exception ex) { throw ex; } finally { if (reader != null) { reader.Close(); } } return(outEntity); }
public DataTable ReadEntityWithExternalFileToDataTable <T>(string key, string condition = "", string columnName = "Col1", string columnPath = "colPath") where T : new() { DoubleASqlMapper mapData = new DoubleASqlMapper(); DataTable dt = new DataTable(); IDataReader reader = null; try { SqlCommand command = base.Read <T>(key); command.CommandText += string.IsNullOrEmpty(condition) ? string.Empty : " " + condition; Type type = typeof(T); object[] attributes = type.GetCustomAttributes(typeof(TableAttribute), true); var tabAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(TableAttribute)); if (tabAttribute != null) { TableAttribute mapsto = tabAttribute as TableAttribute; dt.TableName = mapsto.Name; } OpenConnection(command, this.Connection); reader = command.ExecuteReader(); dt.Load(reader); dt.Columns[columnName].ReadOnly = false; dt.Columns[columnName].MaxLength = -1; foreach (DataRow item in dt.Rows) { item[columnName] = ReadExternalFile(item[columnPath].ToString()); } dt.Columns.Remove(columnPath); CloseCommitConnection(); } catch (Exception ex) { CloseRollbackConnection(); throw ex; } finally { if (reader != null) { reader.Close(); } } return(dt); }
public DataTable ReadEntityToDataTable <T>(string key, string condition = "") where T : new() { DoubleASqlMapper mapData = new DoubleASqlMapper(); DataTable dt = new DataTable(); IDataReader reader = null; try { SqlCommand command = base.Read <T>(key); command.CommandText += string.IsNullOrEmpty(condition) ? string.Empty : " " + condition; Type type = typeof(T); object[] attributes = type.GetCustomAttributes(typeof(TableAttribute), true); var tabAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(TableAttribute)); if (tabAttribute != null) { TableAttribute mapsto = tabAttribute as TableAttribute; dt.TableName = mapsto.Name; } OpenConnection(command, this.Connection); reader = command.ExecuteReader(); dt.Load(reader); CloseCommitConnection(); } catch (Exception ex) { CloseRollbackConnection(); throw ex; } finally { if (reader != null) { reader.Close(); } } return(dt); }