R – SubSonic 2.x Batch Query SQLite

batch-filesubsonictransactions

I'm writing a windows service that import an XML file into a SQLite database.

There are 3,000 odd records that need to be created and i'm using SubSonic 2.2 for the project.

Instead of looping through a list and adding them to the database one by one is there a way to batch query more than 1 new record at a time.

I know the "BatchQuery" object in 3.x would help me here but i was hoping there was something in 2.x that did a similar task.

thanks in advance
Doug

Best Answer

SubSonic 2.x does have a method to perform batch saves.

Here is a sample:

var itemsToSaveCollection = new ItemCollection(); // Your collection type here

foreach (var xmlItem in xmlItems)
{
    var item = new Item(); // Your data model type here
    // Set item values from xml
    itemsToSaveCollection.Add(item);
}

itemsToSaveCollection.BatchSave();