Created
May 29, 2019 04:23
-
-
Save mikependon/d1bdf4feaa0240fc6d9ddb3ab898ee35 to your computer and use it in GitHub Desktop.
IDbConnection (ExecuteQuery and BulkInsert)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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