Пример #1
0
        /// <summary>
        /// Fast bulk insert to copy cells of a grid to the log
        /// </summary>
        /// <param name="gridId">GridId</param>
        public void BulkInsertCellLogs(int gridId)
        {
            var cellLogList = new List<CellLog>();
            var cells = db.Cells.Where(c => c.GridId == gridId).ToList();
            foreach (var c in cells)
            {
                var cellLog = new CellLog(c);
                cellLogList.Add(cellLog);
            }

            var cellLogTable = cellLogList.ToDataTable();

            var connStr = ctx.Database.Connection.ConnectionString;
            using (var bcp = new SqlBulkCopy(connStr))
            {
                bcp.DestinationTableName = "CellLogs";
                bcp.WriteToServer(cellLogTable);
            }
        }
Пример #2
0
 /// <summary>
 /// Add a cell log entry to the database
 /// </summary>
 public void Add(CellLog cellLog, bool saveChanges)
 {
     db.CellLogs.Add(cellLog);
     if(saveChanges) db.SaveChanges();
 }
Пример #3
0
 /// <summary>
 /// Remove a cell log entry from database
 /// </summary>
 public void Remove(CellLog cellLog)
 {
     db.CellLogs.Remove(cellLog);
     db.SaveChanges();
 }
Пример #4
0
 /// <summary>
 /// Add a cell log entry to the database
 /// </summary>
 public void Add(CellLog cellLog)
 {
     Add(cellLog, true);
 }