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

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

Open
rabberbock opened this issue Nov 27, 2023 · 13 comments
Open

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

rabberbock opened this issue Nov 27, 2023 · 13 comments
Assignees

Comments

@rabberbock
Copy link

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

  • EF version: [EF Core v8.0.0]
  • EF Extensions version: [EFE Core v8.101.0]
  • Database Server version: [Postgres 14]
  • Database Provider version (NuGet): [Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0]

Thanks in advance with you help with this. Thanks!

@JonathanMagnan JonathanMagnan self-assigned this Nov 27, 2023
@JonathanMagnan
Copy link
Member

Hello @rabberbock ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

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
Copy link
Author

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

@rabberbock
Copy link
Author

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

@JonathanMagnan
Copy link
Member

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
Copy link
Author

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

@JonathanMagnan
Copy link
Member

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
Copy link
Author

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

@JonathanMagnan
Copy link
Member

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
Copy link
Member

Hello @rabberbock,

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

Let me know if you need more information.

Best regards,
Jon

@rabberbock
Copy link
Author

@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
Copy link
Member

Hello @rabberbock,

Any updates?

Let me know if you need further assistance.

Best regards,

Jon

@rabberbock
Copy link
Author

@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!

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

No branches or pull requests

2 participants