Having issues with large data saving/insert in your .NET applications? EF Core’s BulkInsertAsync could be the solution you need. Simply install EFCore.BulkExtensions from NuGet. Here’s a quick guide to help you get started
🚀 Supercharge Your EF Core Performance with BulkInsertAsync! 🚀
Struggling with large data insertions in your .NET applications? EF Core’s BulkInsertAsync can be a game-changer. Just install EFCore.BulkExtensions from nuget. Here’s a quick guide to help you get started:Why Use BulkInsertAsync?
1. Efficiency: Inserts multiple records in a single database round trip. 2. Performance: Significantly reduces the time taken for bulk operations. 3. Simplicity: Easy to implement with minimal code changes. Example Let’s say we have a Student entity and we want to insert a large list of students into the database.using EFCore.BulkExtensions; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Threading.Tasks; public class Student { public int StudentId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Branch { get; set; } } public class ApplicationDbContext : DbContext { public DbSet<Student> Students { get; set; } } public async Task BulkInsertStudentsAsync(List<Student> students) { using var context = new ApplicationDbContext(); await context.BulkInsertAsync(students); }EF Core SaveChangesAsync:
- 1,000 records: 18 ms
- 10,000 records: 203 ms
- 100,000 records: 2,129 ms
- 1,000 records: 8 ms
- 10,000 records: 76 ms
- 100,000 records: 742 ms1
If you find anything inappropriate please report it here.