alfxp / EntityFrameworkCore.SqlServer.SimpleBulks

A very simple .net core 3.1 library (lightweight, easy to use and customize) that supports bulk insert, bulk update, bulk delete and bulk merge database operations. Lambda Expression is also supported.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Using Dynamic String:

dbct.BulkInsert(rows, "Rows",
    new string[] { "Column1", "Column2", "Column3" });
dbct.BulkInsert(rows.Take(1000), "Rows",
    typeof(Row).GetDbColumnNames("Id"));
dbct.BulkInsert(compositeKeyRows, "CompositeKeyRows",
    new string[] { "Id1", "Id2", "Column1", "Column2", "Column3" });

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

dbct.BulkMerge(rows, "Rows",
    "Id",
    new string[] { "Column1", "Column2" },
    new string[] { "Column1", "Column2", "Column3" });
dbct.BulkMerge(compositeKeyRows, "CompositeKeyRows",
    new 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:

// Register Type - Table Name globaly
TableMapper.Register(typeof(Row), "Rows");
TableMapper.Register(typeof(CompositeKeyRow), "CompositeKeyRows");

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

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

dbct.BulkMerge(rows,
    row => row.Id,
    row => new { row.Column1, row.Column2 },
    row => new { row.Column1, row.Column2, row.Column3 });
dbct.BulkMerge(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, row => row.Id);
dbct.BulkDelete(compositeKeyRows, row => new { row.Id1, row.Id2 });

License

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

About

A very simple .net core 3.1 library (lightweight, easy to use and customize) that supports bulk insert, bulk update, bulk delete and bulk merge database operations. Lambda Expression is also supported.

License:MIT License


Languages

Language:C# 100.0%