FastInsert.SqlServer
1.1.0
dotnet add package FastInsert.SqlServer --version 1.1.0
NuGet\Install-Package FastInsert.SqlServer -Version 1.1.0
<PackageReference Include="FastInsert.SqlServer" Version="1.1.0" />
paket add FastInsert.SqlServer --version 1.1.0
#r "nuget: FastInsert.SqlServer, 1.1.0"
// 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
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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Data.SqlClient (>= 3.1.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.