Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikependon/d1bdf4feaa0240fc6d9ddb3ab898ee35 to your computer and use it in GitHub Desktop.
Save mikependon/d1bdf4feaa0240fc6d9ddb3ab898ee35 to your computer and use it in GitHub Desktop.
IDbConnection (ExecuteQuery and BulkInsert)
// Variables for paging
var lastId = 10000;
var batchSize = 1000000;
var page = 1;
// Create a source connection (Oracle)
using (var sourceConnection = new OracleConnection(sourceConnectionString))
{
// Read the data with target columns
using (var reader = sourceConnection.ExecuteReader("SELECT Id, FirstName, LastName, LastUpdatedUtc, DateInsertedUtc FROM [dbo].[Person] WHERE Id > @Id OFFSET @Offset FETCH NEXT @BatchSize ROWS ONLY;", new { Id = lastId, Offset = (batchSize * page), BatchSize = batchSize }))
{
// Create a destination connection (SqlServer)
using (var destinationConnection = new SqlConnection(destinationConnectionString))
{
// Call the BulkInsert by passing the reader
var insertedRows = destinationConnection.BulkInsert("Person", reader);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment