FastInsert.SqlServer 1.1.0

dotnet add package FastInsert.SqlServer --version 1.1.0                
NuGet\Install-Package FastInsert.SqlServer -Version 1.1.0                
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="FastInsert.SqlServer" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastInsert.SqlServer --version 1.1.0                
#r "nuget: FastInsert.SqlServer, 1.1.0"                
#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 FastInsert.SqlServer as a Cake Addin
#addin nuget:?package=FastInsert.SqlServer&version=1.1.0

// Install FastInsert.SqlServer as a Cake Tool
#tool nuget:?package=FastInsert.SqlServer&version=1.1.0                

FastInsert.SqlServer

Nuget

FastInsert is a .NET library to bulk insert objects into SQL Server tables.

It uses Source Generators to generate the conversion code during the build instead of using reflection during runtime.

Prerequisites

The app needs to target .NET Standard 2.1 or any .NET implementation of it.

Installation

Use the .NET CLI to install the package and its dependencies:

dotnet add package FastInsert.SqlServer

Usage

The classes targeted for conversion should have the BulkInsert attribute:

using FastInsert.Core;

namespace MyProject;

[BulkInsert]
public class Customer
{
}

The batch size will be 1000 by default, but it can be customized:

using FastInsert.Core;

namespace MyProject;

[BulkInsert(5000)]
public class Customer
{
}

By default, the class will be mapped to a table with the same name, but this can be overridden using the System.ComponentModel.DataAnnotations.Schema.TableAttribute attribute:

[Table("Customers")]
public class Customer
{
}

Also by default, the properties will be mapped to columns with the same name. The name can be overridden using the System.ComponentModel.DataAnnotations.Schema.ColumnAttribute attribute:

public class Customer
{
    [Column("phone_number")]
    public string PhoneNumber { get; set; }
}

To insert the data, you need to inject FastInsert.Core.IDataWriter<T>:

public class CustomerService(IDataWriter<Customer> dataWriter)
{
    public Task SaveCustomers(IEnumerable<Customer> customers, CancellationToken cancellationToken)
    {
        return dataWriter.WriteAsync(customers, cancellationToken);
    }
}

You can configure dependency injection by calling an extension method:

using FastInsert.DependencyInjection;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddFastInsert();

Contributing

Pull requests are welcome, but please open an issue first to discuss your idea.

License

Distributed under the GPL-3.0 License. See LICENSE for more information.

Changelog

1.1.0 (2024-02-20)

Add support for nested classes

1.0.0 (2024-01-23)

First release

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
1.1.0 134 2/20/2024
1.0.0 131 1/23/2024