question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow bulk usage of sequence while using `DbContext.Set<T>.AddRange(Async)`

See original GitHub issue

Lately, I was trying to insert bulk records on multiple tables those inserts were just one-time inserts and I didn’t want to stress myself out. So I tried to do it in a casual way: Create a list of entities add them via AddRangeAsync and save the changes. While doing this I realized this process taking a fairly long time. And enabled detailed logs and it was the flooding of select nextval queries. So it was literally 1 nexval query per entity added indeed. And %90 of the time spent was getting these sequence numbers from the DB. It should be done in one round trip to get the required number of sequences while doing these inserts. Postgresql allows us to write queries like this: select nextval('my_seq') from generate_series(1,3); so in theory we can get them in a bulk way. So I hope it is doable in a provider level and it’s not a limitation of EF itself.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Jun 3, 2021

It would have been awesome configuration if did r.StartsAt(1).IncrementsBy(1000)

1reaction
3ldarcommented, Jun 3, 2021

@roji your quick answer is much appreciated. Sorry for taking your time for this kind of silly misconception.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to increase insert speed using Bulk ...
I have used Entity Framework to insert data into SQL tables. For larger number of records, instead of Add() , I have used...
Read more >
Entity Framework and slow bulk INSERTs - Rick Strahl
While inserting a large number of records into a SQL database using EF Code First, I ran into some stunningly slow performance.
Read more >
DbContext.AddRangeAsync Method
This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.
Read more >
Admin/EFCore.BulkExtensions
Usage. It's pretty simple and straightforward. Bulk Extensions are made on DbContext class and can be used like this (supported both regular and...
Read more >
Insert Records in Entity Framework Core
Entity Framework Core Bulk Insert. The DbContext.AddRange() method is used to bulk insert multiple records on the database at the same time.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found