1

While using XML based database, can I write multiple records at once to prevent excessive disk writes? I don't want to use XML file directly (to not prevent SQL migration - I might switch to SQL in the future).

I want to add 5000+ records -in a job queue- and update/delete them later, in a short period -when a job finished-.

While queue is processing I keep the record list in memory, at the end I need to write them back.

In the case of power loss, all completed jobs should be processed again, that's the con, but very rare, since the server is backed up by UPS.

daniele3004
  • 13,072
  • 12
  • 67
  • 75
Nime Cloud
  • 6,162
  • 14
  • 43
  • 75
  • Do you want a transaction in during XML writing? – daniele3004 Nov 24 '15 at 13:25
  • Use a DataAdapter to read/update database. You can fill a DataTable from the DataAdapter then update the data in the DataTable. Later use the Update method to save changes back to the database. – jdweng Nov 24 '15 at 13:42

1 Answers1

2

DataConnection class supports overloads to add, delete or update multiple records at the same time.

using(var conn = new DataConnection()) {
  var toBeUpdated = new List<MyDataType>();
  var toBeDeleted = new List<MyDataType>();

 var dataset = conn.Get<MyDataType>().ToList();
 for(var data in dataset) {
   if(...) {
    .....
    toBeUpdated.Add(data);
   }
 }
 .....
 .....

 conn.Update(toBeUpdated);
 conn.Delete(toBeDeleted);
}
Dmitry Dzygin
  • 1,258
  • 13
  • 26