Question

I have an IEnumerable and I would like to do a batch insert (240,000+ records). I've been perusing the forums and SO and I haven't been able to come up with something that works...

The other catch is that I need to be able to specify a different provider, as these records need to be inserted into a database with a different connection string.

Basically, something like this:

IEnumerable<MyObject> records = GetRecords();
SubSonicDooHickey.BatchSave(records, "differentSubsonicProvider")

I know that isn't exact, but something along those lines...

I've tried:

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();

(and several others) but couldn't get them to work...the above code didn't work because I couldn't find an appropriate collection from subsonic that had a .BatchSave function on it, and I also wouldn't know how to change the provider.

Was it helpful?

Solution

Turns out I didn't need this, but I was able to get this to work using a command:

var sql = "insert into foo(col1) values('@Param1'),('@Param2')";

var cmd = new QueryCommand(sql, repositoryName);
cmd.AddParameter("@Param1", "value1", DbType.String);
cmd.AddParameter("@Param2", "value2", DbType.String);
DataService.ExecuteQuery(cmd)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top