-
SqlBulkTools.FSharp is a wrapper around SqlBulkTools which provides F# computation expressions:
bulkInsert,bulkInsertAsync,bulkInsertTaskbulkUpdate,bulkUpdateAsync,bulkUpdateTaskbulkUpsert,bulkUpsertAsync,bulkUpsertTaskbulkDelete,bulkDeleteAsync,bulkDeleteTask
-
SqlBulkTools.FSharp v1.0.0 currently relies on a fork of SqlBulkTools by fretje which migrated to
Microsoft.Data.SqlClient.- (Previous versions used
System.Data.SqlClient.) - If you need to use System.Data.SqlClient, there is also a fork by fretje called SqlBulkTools.SystemDataSqlClient
- (Previous versions used
dotnet add package SqlBulkTools.FSharp
open SqlBulkTools.FSharp
open Microsoft.Data.SqlClient
use conn = new new SqlConnection("conn str..")
let count =
bulkInsert conn {
for user in users do
table "Users"
column user.Id
columnMap user.FirstName "FName"
columnMap user.LastName "LName"
column user.SSN
identity user.Id
} use conn = new new SqlConnection("conn str..")
// Explicit transaction is optional
use tx = conn.BeginTransaction()
bulkUpdate conn {
for row in rows do
transaction tx
table (nameof ctx.Dbo.Orders)
column row.Id
column row.OrderDate
column row.CustomerEmail
column row.CustomerAddress
column row.CustomerCity
column row.CustomerState
column row.CustomerZip
matchTargetOn row.Id
}
if count > 0
then tx.Commit()
else tx.Rollback()bulkUpsert conn {
for row in rows do
table (nameof ctx.Dbo.Orders)
column row.Id
column row.OrderDate
column row.CustomerEmail
column row.CustomerAddress
column row.CustomerCity
column row.CustomerState
column row.CustomerZip
// to match against multiple columns:
matchTargetOn row.OrderDate
matchTargetOn row.Email
}bulkDelete conn {
for sheet in deletedSheets do
table "Sheets"
column sheet.Id
matchTargetOn sheet.Id
}You can use the underlying C# fluent API if the F# computation expression builders don't meet your needs:
Please view the original C# README.md for full documentation: