Skip to content

A super easy way to bulk copy your CLR objects to SQL Server — no fuss, no boilerplate.

License

Notifications You must be signed in to change notification settings

xin9le/ObjectBulkCopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectBulkCopy

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.

Releases Nuget packages GitHub license

Support Platform

  • .NET 8.0+

Note

It is planned to be extended to .NET Standard in the future.

How to use

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);
}

Installation

Getting started from downloading NuGet package.

dotnet add package ObjectBulkCopy

License

This library is provided under MIT License.

Author

Takaaki Suzuki (a.k.a @xin9le) is software developer in Japan who awarded Microsoft MVP for Developer Technologies (C#) since July 2012.

About

A super easy way to bulk copy your CLR objects to SQL Server — no fuss, no boilerplate.

Resources

License

Stars

Watchers

Forks

Packages

No packages published