A super simple C# library for performing SqlBulkCopy
directly on your CLR objects. No need to manually map properties--just plug in your list of objects and copy them to SQL Server with minimal setup. Ideal for high-performance data inserts in .NET applications.
- .NET 8.0+
Note
It is planned to be extended to .NET Standard in the future.
using System.ComponentModel.DataAnnotations.Schema;
[Table("Users")] // must set table name
public class User
{
[Column("Id", Order = 0)] // must set zero-based order
public required int Id { get; init; }
[Column("Name", Order = 1)]
public required string Name { get; init; }
}
using ObjectBulkCopy;
using (var connection = new SqlConnection(...))
{
User[] records
= [
new(){ Id = 0, Name = "xin9le" },
new(){ Id = 1, Name = "Takaaki Suzuki" },
];
const SqlBulkCopyOptions options = SqlBulkCopyOptions.Default;
int? timeout = null;
var affectedCount = await connection.BulkInsertAsync(records, options, timeout, cancellationToken);
}
Getting started from downloading NuGet package.
dotnet add package ObjectBulkCopy
This library is provided under MIT License.
Takaaki Suzuki (a.k.a @xin9le) is software developer in Japan who awarded Microsoft MVP for Developer Technologies (C#) since July 2012.