Reputation: 19153
I am transferring documents held in a SqlServer database to a RavenDB database. The process is simple but, in line with RavenDB's 'safety first' principle, only the first 128 documents are actually stored.
I understand why this is the case and I also know this limit can be adjusted for the document store as a whole, however, given that storing more than 128 docs in a given operation is not too unusual, I would like to know what the best practice is?
Here is my code to show an example of how I get around the limit. Is there a more elegant way?
public static void CopyFromSqlServerToRaven(IDocumentSession db)
{
var counter = 0;
using (var connection = new SqlConnection(SqlConnectionString))
{
var command = new SqlCommand(SqlGetContentItems, connection);
command.Connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
counter++;
db.Store(new ContentItem
{
Id = reader["Id"].ToString(),
Title = reader["Name"].ToString(),
Description = reader["ShortDescription"].ToString()
});
if (counter < 128) continue;
db.SaveChanges();
counter = 0;
}
}
db.SaveChanges();
}
}
Upvotes: 1
Views: 413
Reputation: 9163
You can store how much documents that you want in one operation. No need to save changes in chunks.
Upvotes: 2