Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulkSaveChanges throws NullReferenceException, but SaveChanges works #1311

Closed
asfarley opened this issue Nov 10, 2023 · 3 comments
Closed

BulkSaveChanges throws NullReferenceException, but SaveChanges works #1311

asfarley opened this issue Nov 10, 2023 · 3 comments

Comments

@asfarley
Copy link

Hi,

I've just tested out your library as a replacement for the dbcontext.SaveChanges function, but I'm getting an exception:

   at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.<>c.<SaveChangesAsync>b__2_3(IEntityType e)
   at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.<>c__DisplayClass2_0.<SaveChangesAsync>b__6(<>f__AnonymousType1`4 g)
   at Medallion.Collections.TopologicalSorter.<TopologicalSort>d__0`1.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at System.Linq.Enumerable.ConcatIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.<SaveChangesAsync>d__2.MoveNext()
   at EFCore.BulkExtensions.DbContextBulkTransactionSaveChanges.SaveChanges(DbContext context, BulkConfig bulkConfig, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkTransaction.Execute[T](DbContext context, Type type, IEnumerable`1 entities, OperationType operationType, BulkConfig bulkConfig, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkExtensions.BulkSaveChanges(DbContext context, BulkConfig bulkConfig, Action`1 progress)
   at VSControls.VSDatabaseManager.SaveProjectToDb(Project Proj, String path) in C:\VitalSim\Vital-Sim-.NET\VSControls\VSDatabaseManager.cs:line 353

My understanding from the documentation is that the function dbcontext.BulkSaveChanges should be a drop-in replacement for dbcontext.SaveChanges. Do you have any suggestions for troubleshooting steps?

@killnine
Copy link

killnine commented Jan 4, 2024

Exact same issue here. I was evaluating to see if we could speed up bulk-inserts in some utilities with this library but it seemed to fall on its face with this.

SaveChanges works fine but using this throws an Object Ref exception

FWIW - I am running .NET 8.0, so perhaps it's an issue with newer .NET release?

@asfarley
Copy link
Author

asfarley commented Jan 4, 2024

My application is targeting .NET 6.0

@borisdj
Copy link
Owner

borisdj commented Jan 4, 2024

Can you make a sample where the issue would be reproducible, code snipped of Entities their Db context config and Insert method. Or to write a test, take a look at existing one for BulkSaveChanges in the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants