Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

jake-carpenter/easy-bulk-copy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED

I lost access to the MS account that owns the NuGet package for this project. A replacement project is planned. - May 31, 2024

EasyBulkCopy

Easy and automatic mapping for SqlBulkCopy

Installation

  • Option 1: Install via package manager
  • Option 2: Install via NuGet
Install-Package EasyBulkCopy
  • Option 3: Install via dotnet command line interface
dotnet add package EasyBulkCopy

Usage

Create classes that map to your MSSQL tables and decorate them with the attribute to provide the table name

[BulkTableName("dbo.MyTable")]
public class MyTable
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTimeOffset CreatedDate { get; set; }
}

Register your classes in the .NET Core DI container

  • Option 1: Piecemeal registration
public void ConfigureServices(IServiceCollection services)
{
    services.UseEasyBulkCopy();
    services.RegisterBulkInsertType<MyTable>();
}
  • Option 2: Scan assembly and automatically register decorated types
public void ConfigureServices(IServiceCollection services)
{
    services.UseEasyBulkCopy();
    services.RegisterBulkInsertTypesInAssembly(Assembly.GetExecutingAssembly());
}

Inject the IBulkInserter interface where needed

public class Foo
{
    // ...
    public Foo(IBulkInserter bulkInserter)
    {
        _bulkInserter = bulkInserter
        _connectionString = "Server=localhost;Database=master;"
    }

    public async Task Write(IEnumerable<MyTable> rows)
    {
        await _bulkInserter.Insert(_connectionString, rows);
    }
}

About

Easy and automatic mapping for SqlBulkCopy

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages