SqlBulkHelpers 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package SqlBulkHelpers --version 1.0.4
NuGet\Install-Package SqlBulkHelpers -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SqlBulkHelpers" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SqlBulkHelpers --version 1.0.4
#r "nuget: SqlBulkHelpers, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SqlBulkHelpers as a Cake Addin
#addin nuget:?package=SqlBulkHelpers&version=1.0.4

// Install SqlBulkHelpers as a Cake Tool
#tool nuget:?package=SqlBulkHelpers&version=1.0.4

SqlBulkHelpers

A library for efficient and high performance bulk insert and update of data, into a Sql Database, from C# applications. This library leverages the power of the C# SqlBulkCopy classes, while augmenting with the following key benefits:

  • Provides a simplified facade for interacting with the SqlBulkCopy API.
    • The Performance improvements have been DRAMATIC!
  • Provides enhanced support for ORM (e.g. Dapper) based inserts/updates with the SqlBulkCopy API.
    • It's obviously easy to bulk load data from the DB into model/objects via optimized queries (e.g. Dapper), but inserting and updating is a whole different story).
  • Provides support for Database Tables that utilize an Identity Id column as the Primary Key.
    • It dynamically retrieves the new Identity column value and populates them back into the Objects provided so your update will result in your models automagically having their PKey (Identity) populated!

The SqlBulkCopy API provides fantastic performance benefits, but retrieving the Identity values for Primary Keys that are auto-generated is not a default capability. And as it turns out, this is not a trivial task despite the significant benefits it provides for developers.

Providing support for a table with an Identity Column as the Primary Key is the critical reason for developing this library. There is alot of good information on Stack Overflow and other web resources that provide various levels of help for this kind of functionality, but there are few (if any) fully developed solutions to really help others find an efficient way to do this end-to-end.

So, that was the goal of this library, to provide and end-to-end solution to either a) leverage directly if it fits your use-cases, or b) use as a model to adapt to your use case!

I hope that it helps others on their projects as much as it has helped ours.

Usage:

Usage is very simple if you use a lightweigth Model (e.g. ORM model via Dapper) to load data from your tables...

    //Initialize the Sql Connection Provider (or manually create your own Sql DB Connection...)
    //NOTE: This interface provides a great abstraction that most projects don't take the time to do, 
    //          so it is provided here for convenience (e.g. extremely helpful with DI).
    ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlBulkHelpersConnectionProvider.Default;

    //Initialize large list of Data to Insert or Update in a Table
    List<TestElement> testData = SqlBulkHelpersSample.CreateTestData(1000);

    //Bulk Inserting is now as easy as:
    //  1) Initialize the DB Connection & Transaction (IDisposable)
    //  2) Instantiate the SqlBulkIdentityHelper class with ORM Model Type...
    //  3) Execute the insert/update (e.g. Convenience method allows InsertOrUpdate in one execution!)
    using (SqlConnection conn = await sqlConnectionProvider.NewConnectionAsync())
    using (SqlTransaction transaction = conn.BeginTransaction())
    {
        ISqlBulkHelper<TestElement> sqlBulkIdentityHelper = new SqlBulkIdentityHelper<TestElement>();

        await sqlBulkIdentityHelper.BulkInsertOrUpdateAsync(testData, "TestTableName", transaction);

        transaction.Commit();
    }

NOTE: More Sample code is provided in the Sample App..._

  
MIT License

Copyright (c) 2019 - Brandon Bernard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.4.4 72 3/22/2024
2.4.3 1,160 12/15/2023
2.4.2 266 11/7/2023
2.4.1 151 10/24/2023
2.4.0 1,170 9/11/2023
2.3.1 857 9/2/2023
2.3.0 327 8/8/2023
2.2.3 155 8/4/2023
2.2.2 1,698 5/25/2023
2.1.0 364 3/3/2023
2.0.0 354 2/16/2023
1.4.0 1,905 10/1/2022
1.3.0 394 9/28/2022
1.2.0 566 7/14/2022
1.1.0 2,112 12/2/2021
1.0.7 265 12/2/2021
1.0.6.2 568 12/10/2020
1.0.6.1 373 12/10/2020
1.0.6 465 12/9/2020
1.0.5 436 12/9/2020
1.0.4 775 11/1/2019
1.0.2 486 10/29/2019

Fixed bug in dynamic initialization of SqlBulkHelpersConnectionProvider and SqlBulkHelpersDBSchemaLoader when not using the Default instances that automtically load the connection string from the application configuration setting.