Skip to content
A very simple .net core 3.1 library (contains only few hundred lines of code) that supports bulk insert, bulk update, bulk delete and bulk merge database operations
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md

README.md

EntityFrameworkCore.SqlServer.SimpleBulks

This is a very simple .net core library that can help to work with large number of records using the SqlBulkCopy class.  

Overview

This library provides extension methods so that you can use with your EntityFrameworkCore DbContext instance: DbContextExtensions.cs or you can use SqlConnectionExtensions.cs to work directly with a SqlConnection instance.

EntityFrameworkCore.SqlServer.SimpleBulks supports:

  • Bulk Insert
  • Bulk Update
  • Bulk Delete
  • Bulk Merge

Examples

private const string _connectionString = "Server=.;Database=SimpleBulks;User Id=xxx;Password=xxx;MultipleActiveResultSets=true";
  • Build and run.

Using Dynamic String:

dbct.BulkInsert(rows, "Rows",
    "Column1", "Column2", "Column3");
dbct.BulkInsert(compositeKeyRows, "CompositeKeyRows",
    "Id1", "Id2", "Column1", "Column2", "Column3");

dbct.BulkUpdate(rows, "Rows",
    "Id",
    "Column3", "Column2");
dbct.BulkUpdate(compositeKeyRows, "CompositeKeyRows",
    new List<string> { "Id1", "Id2" },
    "Column3", "Column2");

dbct.BulkMerge(rows, "Rows",
    "Id",
    new string[] { "Column1", "Column2" },
    new string[] { "Column1", "Column2", "Column3" });
dbct.BulkMerge(compositeKeyRows, "CompositeKeyRows",
    new List<string> { "Id1", "Id2" },
    new string[] { "Column1", "Column2", "Column3" },
    new string[] { "Id1", "Id2", "Column1", "Column2", "Column3" });

dbct.BulkDelete(rows, "Rows", "Id");
dbct.BulkDelete(compositeKeyRows, "CompositeKeyRows", new List<string> { "Id1", "Id2" });

Using Lambda Expression:

dbct.BulkInsert(rows, "Rows",
    row => new { row.Column1, row.Column2, row.Column3 });
dbct.BulkInsert(compositeKeyRows, "CompositeKeyRows",
    row => new { row.Id1, row.Id2, row.Column1, row.Column2, row.Column3 });

dbct.BulkUpdate(rows, "Rows",
    row => row.Id,
    row => new { row.Column3, row.Column2 });
dbct.BulkUpdate(compositeKeyRows, "CompositeKeyRows",
    row => new { row.Id1, row.Id2 },
    row => new { row.Column3, row.Column2 });

dbct.BulkMerge(rows, "Rows",
    row => row.Id,
    row => new { row.Column1, row.Column2 },
    row => new { row.Column1, row.Column2, row.Column3 });
dbct.BulkMerge(compositeKeyRows, "CompositeKeyRows",
    row => new { row.Id1, row.Id2 },
    row => new { row.Column1, row.Column2, row.Column3 },
    row => new { row.Id1, row.Id2, row.Column1, row.Column2, row.Column3 });
                        
dbct.BulkDelete(rows, "Rows", row => row.Id);
dbct.BulkDelete(compositeKeyRows, "CompositeKeyRows", row => new { row.Id1, row.Id2 });

License

EntityFrameworkCore.SqlServer.SimpleBulks is licensed under the MIT license.

You can’t perform that action at this time.