/// <summary> /// Initializes a new instance of the <see cref="DataBaseCrudTest"/> class. /// </summary> public DataBaseCrudTest() { DbSqlConnection connection = new DbSqlConnection(); AdoSqlServerDataLayerFactory factory = new AdoSqlServerDataLayerFactory(connection); _context = new DbContext(factory); }
public IEnumerable <TEntity> RunProc <TEntity>(string commandText, params SqlParameter[] parameters) { var items = new List <TEntity>(); // command settings DbSqlCommand.Parameters.Clear(); DbSqlCommand.CommandText = commandText; DbSqlCommand.CommandType = CommandType.StoredProcedure; // add params if (parameters?.Length > 0) { DbSqlCommand.Parameters.AddRange(parameters); } // open a connection if (DbSqlConnection.State == ConnectionState.Closed) { DbSqlConnection.Open(); } // fetch record using (var data = DbSqlCommand.ExecuteReader()) { while (data.Read()) { items.Add(MapEntity <TEntity>(data)); } } return(items); }
/// <summary> /// Initializes a new instance of the <see cref="DataBaseCrudTest" /> class. /// </summary> public LinqToSqlDataBaseCrudTest() { DbSqlConnection connection = new DbSqlConnection(); var factory = new LinqToSqlDataLayerFactory(connection); _context = new DbContext(factory); }
public void SaveChanges() { try { DbSqlConnection.Open(); for (int i = 0; i < ListSqlSentence.Count; i++) { ListSqlSentence[i].ExecuteNonQuery(); ListFnActions[i](); } } catch (SqlException ex) { throw ex; } finally { if (DbSqlConnection.State == ConnectionState.Open) { DbSqlConnection.Close(); } if (ListFnActions != null) { ListFnActions.Clear(); } if (ListSqlSentence != null) { ListSqlSentence.Clear(); } } }
public void Dispose() { if (DbSqlConnection.State == ConnectionState.Open) { DbSqlConnection.Close(); } DbSqlCommand.Dispose(); DbSqlConnection.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="ExcelReportsTest"/> class. /// </summary> public ExcelReportsTest() { DbSqlConnection connection = new DbSqlConnection(); ExcelConnection excelConnection = new ExcelConnection(); AdoSqlServerDataLayerFactory factory = new AdoSqlServerDataLayerFactory(connection); AdoExcelDataLayerFactory excelFactory = new AdoExcelDataLayerFactory(excelConnection); _dbContext = new DbContext(factory); _excelContext = new ExcelContext(excelFactory); }
/// <summary> /// Initializes a new instance of the <see cref="LinqToSqlDataLayerFactory"/> class. /// </summary> /// <param name="connection">The connection.</param> public LinqToSqlDataLayerFactory(DbSqlConnection connection) : base(connection) { }
/// <summary> /// Initializes a new instance of the <see cref="SqlServerDataLayerFactory"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <exception cref="ArgumentNullException">connection</exception> public SqlServerDataLayerFactory(DbSqlConnection connection) { _connection = connection ?? throw new ArgumentNullException(nameof(connection)); }