zzzprojects / EntityFramework-Extensions

Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
https://entityframework-extensions.net
341 stars 57 forks source link

BulkInsert Exception using NpgSql and jsonb in .NET 8 #560

Open rabberbock opened 9 months ago

rabberbock commented 9 months ago

Description

Bulk Insert throws an exception when the entity has a jsonb column. The jsonb column mapping is set in OnModelCreating.

Exception

Exception message: The given key 'EntityType: BlogMetadata Owned' was not present in the dictionary.
Stack trace:    at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey key)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Z.EntityFramework.Extensions.PropertyZInfo.GetFlatternHierarchyPath(IEntityType entityType)
   at .[](BulkOperation`1 this, BulkOperationActionType , Boolean , Dictionary`2 , IEntityType , List`1 , HashSet`1 , Dictionary`2 )
   at .[](BulkOperation`1 this, IEntityType , BulkOperationActionType )
   at .[](BulkOperation`1 this, DbContext , IEntityType , IEnumerable`1 , BulkOperationActionType )
   at .BulkInsert[T](DbContext this, IEntityType entityType, IEnumerable`1 list, Action`1 options, SavingSelector savingSelector, Boolean forceSpecificTypeMapping, Boolean isOptimized)
   at .[](DbContext , SavingSelector , Action`1 )
   at .[](DbContext ,  , BulkOperationActionType , Action`1 )
   at .BulkInsert[T](DbContext this, IEnumerable`1 entities, Action`1 options, Boolean isBulkSaveChanges, Boolean isOptimized)
   at DbContextExtensions.BulkInsert[T](DbContext this, IEnumerable`1 entities, Action`1 options)
   at DbContextExtensions.`1.()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at DbContextExtensions.BulkInsertAsync[T](DbContext this, IEnumerable`1 entities, Action`1 options, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in C:\Users\rabbe\Projects\Samples\EFGetStarted\Program.cs:line 61

Fiddle or Project (Optional)

https://github.com/rabberbock/BulkInsertJsonb/tree/master

Further technical details

Thanks in advance with you help with this. Thanks!

JonathanMagnan commented 9 months ago

Hello @rabberbock ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

JonathanMagnan commented 9 months ago

Hello @rabberbock ,

Here is a small update:

We have found the issue and know how to fix it.

However, that's not an easy fix, as we need to look at the logic about how EF Core is currently transforming entity into json (they have their own json writer inside the EF Core code for this).

So that's definitely something we will look to support, but the fix might come more in January.

Best Regards,

Jon

rabberbock commented 8 months ago

@JonathanMagnan Thanks for the update! Looking forward to that fix, thanks!

rabberbock commented 5 months ago

@JonathanMagnan Just curious if you had any updates on your end on this. Thanks!

JonathanMagnan commented 5 months ago

Hello @rabberbock ,

We are currently completing our top priority (it should be completed by Friday).

Fixing this jsonb column will become the next top priority as soon as it's completed. I'm not sure how long it will take, but we usually try to push as fast as possible our top priority. So I don't have an ETA yet, but it will become our main focus starting from next week, so I should be able to give you an update very soon.

Best Regards,

Jon

rabberbock commented 4 months ago

@JonathanMagnan Just wanted to check in to see if you have an idea when this will be completed? Thanks either way!

JonathanMagnan commented 4 months ago

Hello @rabberbock ,

A new version has been released a few hours ago. I will make the release notes later, but you can already try the latest version.

It's still not 100% perfect (we are still working on more complex scenarios such as Owned Many), but most common scenario should already work.

I will let you know more soon.

Best Regards,

Jon

rabberbock commented 4 months ago

@JonathanMagnan Awesome, thanks for the update! Will let you know if we run into any issues.

JonathanMagnan commented 4 months ago

Awesome @rabberbock ,

You can see the release note here, but there is not much additional information besides what I just said.

Sure, we will be happy to look at it and try to support it if you run into any issues. We are still working on the ToJson Mapping for the more complex scenario.

Best Regards,

Jon

JonathanMagnan commented 4 months ago

Hello @rabberbock,

Since our last conversation, we haven't heard from you.

Let me know if you need more information.

Best regards, Jon

rabberbock commented 4 months ago

@JonathanMagnan I did a quick test and I am still running into issues, will post with more relevant details when I get a chance. My guess is that we will need the more complex scenario support. Thanks!

JonathanMagnan commented 3 months ago

Hello @rabberbock,

Any updates?

Let me know if you need further assistance.

Best regards,

Jon

rabberbock commented 3 months ago

@JonathanMagnan Sorry for the delay! Just got around to doing some testing and all errors I got were ef issues not related to this library. So everything seems to working great after this update. Thanks!