N.EntityFrameworkCore.Extensions icon indicating copy to clipboard operation
N.EntityFrameworkCore.Extensions copied to clipboard

Bulk Insert - Trigger Enabled Option

Open awaais78 opened this issue 1 year ago • 1 comments

Using SQL Server - If i need to bulk insert on table , which has triggers enabled , that should be fired as well.

awaais78 avatar Jan 15 '25 12:01 awaais78

`awaais78,

In order to call BulkInsert and call any triggers on it at the same time, you would use the following code: ` var dbContext = SetupDbContext(false);

    var products = new List<ProductWithTrigger>();
    for (int i = 1; i < 1000; i++)
    {
        products.Add(new ProductWithTrigger { Id = i.ToString(), Price = 1.57M, StatusString="InStock" });
    }
    int rowsInserted = dbContext.BulkInsert(products, options => {
        options.AutoMapOutput = false;
        options.BulkCopyOptions = SqlBulkCopyOptions.FireTriggers;
    });

`

NorthernLight1 avatar May 09 '25 02:05 NorthernLight1