BulkInsert() throws exceptions with .net10 Preview 5 due to IReadOnlyEntityType no longer having method GetDiscriminatorValue()
When trying any bulk insert operations with .Net 10 Preview 5, I get the following exceptions:
Method not found: 'System.Object Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType.GetDiscriminatorValue()'.
at EFCore.BulkExtensions.SqlAdapters.Sqlite.SqliteAdapter.LoadSqliteValues[T](TableInfo tableInfo, T entity, SqliteCommand command, DbContext dbContext)
at EFCore.BulkExtensions.SqlAdapters.Sqlite.SqliteAdapter.LoadSqliteValues[T](TableInfo tableInfo, T entity, SqliteCommand command, DbContext dbContext)
at EFCore.BulkExtensions.SqlAdapters.Sqlite.SqliteAdapter.<MergeAsync>d__7`1.MoveNext()
at EFCore.BulkExtensions.SqlAdapters.Sqlite.SqliteAdapter.<MergeAsync>d__7`1.MoveNext()
at EFCore.BulkExtensions.SqlAdapters.Sqlite.SqliteAdapter.Merge[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress)
at EFCore.BulkExtensions.SqlBulkOperation.Merge[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, 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.BulkInsert[T](DbContext context, IEnumerable`1 entities, BulkConfig bulkConfig, Action`1 progress, Type type)
It appears that the IReadOnlyEntityType interface in Preview 5 no longer has member GetDiscriminatorValue(). Looking at the IReadOnlyEntityType sources it seems that this is a recent change: https://github.com/dotnet/efcore/blob/main/src/EFCore/Metadata/IReadOnlyEntityType.cs
This is still happening with .Net 10 RC1.
@borisdj Any chance you can have a look at this? .Net 10 RC1 is out already and soon we will have RTM. I think EFCore refactored their code so this method is now an extension. Basically BulkInsert cannot be used with EFCore 10
@philipag if you already have . Net10 installed try to debug it with code change
from
columnsDict.Add(discriminatorColumn, entityType.GetDiscriminatorValue());
to
var discriminator = entityType.GetDiscriminatorProperty()?.PropertyInfo?.GetValue(entity); columnsDict.Add(discriminatorColumn, discriminatorValue );
@borisdj I am currently just using the Nuget as-is so am not set up for debugging the bulk extensions. But when a new Nuget is published with this fix I will certainly test it...
On .NET10, I am getting this exception:
System.MissingMethodException Method not found: 'Boolean Microsoft.EntityFrameworkCore.Metadata.IReadOnlyNavigationBase.get_IsCollection()'. at EFCore.BulkExtensions.TableInfo.<>c__189`1.<LoadData>b__189_51(INavigation a)
v10 is out next week, will check it then, first thing.
On .NET10, I am getting this exception:
System.MissingMethodException Method not found: 'Boolean Microsoft.EntityFrameworkCore.Metadata.IReadOnlyNavigationBase.get_IsCollection()'. at EFCore.BulkExtensions.TableInfo.<>c__189`1.b__189_51(INavigation a)
See the same thing in RC2.
Thanks for all your work Boris!
v10 is out now and the problem is still there
Method not found: 'System.Object Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType.GetDiscriminatorValue()'.
Because of this I can't migrate my projects to net10.
On .NET10, I am getting this exception:
System.MissingMethodException Method not found: 'Boolean Microsoft.EntityFrameworkCore.Metadata.IReadOnlyNavigationBase.get_IsCollection()'. at EFCore.BulkExtensions.TableInfo.<>c__189`1.b__189_51(INavigation a)
Because of this I can't migrate my projects to net10.
Yes, you can. Instead of posting a complaint about how you can't upgrade to .Net 10 on the day it was released, why not either find a workaround, or submit a PR to fix it? @borisdj doesn't get paid to maintain EfCore.BulkExtensions, and you got it for free. There are plenty of licensed alternatives you can use instead.
Alternatively, you can write code like this, which will fall back to using standard EF Core to do the updates/inserts. It'll be marginally slower, but it'll work just fine with .Net 10.
People need to stop acting so entitled about FOSS.
Because of this I can't migrate my projects to net10.
On .NET10, I am getting this exception:
System.MissingMethodException Method not found: 'Boolean Microsoft.EntityFrameworkCore.Metadata.IReadOnlyNavigationBase.get_IsCollection()'. at EFCore.BulkExtensions.TableInfo.<>c__189`1.b__189_51(INavigation a)
In previous versions, IReadOnlyNavigationBase had an IsCollection property. However, this was removed in v10.
I believe casting in relevant places will resolve the issue. For example;
var navigations = entry.Navigations.Where(a => a.IsLoaded); foreach (var n in navigations.Where(a => a.Metadata.IsCollection))var navigations = entry.Navigations.Where(a => a.IsLoaded); foreach (var n in navigations.Where(a => a.Metadata is IReadOnlyPropertyBase p && p.IsCollection))
I had revised my comment like this last night, but it wasn’t posted. I left that comment to emphasize the importance of this issue, so it’s unfortunate that you perceived it as an attack and responded in such a hostile manner.
The value of your library is undeniable, and I’m genuinely grateful for the work you’ve done.
But it’s unreasonable to expect me or anyone else to review the entire codebase and handle the .NET 10 migration on our own. At this point, the proper response to such a comment is actually quite simple — there’s no need to get defensive. You could just say whether you plan to handle this migration and, if so, when.
If you already have a branch locally for this migration, it wouldn’t make sense for me to make major changes to your library. But if you open a branch for it, I’ll gladly do my best to help implement the necessary solution. On the other hand, if you don’t plan to proceed with the migration or maintain the project, I can fork it and take on the effort myself.
If you're replying to me, then you should probably be aware that I am not the maintainer of BulkExtensions (that is @borisdj) - I am just a user of the library. I was just pointing out that your comment came across as a bit entitled, and that this particular error does not prevent your upgrade to .Net 10 at all.
If you have a fix for this, then submit a PR. If not, then be patient.....
@Webreaper and @bugrakosen relax, we all can stay polite both with the issues nad comments. New nuget v10 will be published in a few days, just have to figure out first how to resolve some breaking changes with .Net10 target, and also and the moment it might only be for SqlServer since other providers (pg, my, ..) did not yet update their adapter, but I expect they will do it till end of this month.
Thanks for your reply @borisdj . Yesterday, I tried upgrading the project to .NET 10 myself, but I ran into quite a few issues. If you already have a branch where you’re working on this, I’d love to take a look and see what I can do to help with it.
Thx, not yet, will add here a note once commit is made.
@borisdj Dumb attempt to support .NET10 https://github.com/borisdj/EFCore.BulkExtensions/pull/1891
v 10.0.0-rc.1 At the moment published Nugets as .RC are SqlServer and Sqlite In Solution other projects are temporary unLoaded. Changes are made in the main branch.
rc.2 publish with these fixes for DiscriminatorValue and for IsCollection.
i can confirm, that bulkinsertasync with SetOutputIdentity now works with EFCore 10 release and BulkExtentions 10.0.0-rc.2
Hi guys, I just stumbled in the same issue https://github.com/borisdj/EFCore.BulkExtensions/issues/1900 which I can now close since it's a replica of this.
Can someone please tell me from which NuGet repository you're getting the 10.0.0-rc2 version, because it's not published in the main one.
https://www.nuget.org/packages/EFCore.BulkExtensions/
Thanks in advance
@claylaut That's your guy: https://www.nuget.org/packages/EFCore.BulkExtensions.SqlServer/#versions-body-tab
Perfect, thank you so much, it worked
I'm waiting for the release of the appropriate version of the npgsql package for 10 🥹
Hi, any publish update for postgresql package? got the same issue here with dotnet 10.
Hi, any publish update for postgresql package? got the same issue here with dotnet 10.
Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0 version has been released and I created a PR for this. @borisdj fyi.
Thx @bugrakosen Published on Nuget EFCore.BulkExtensions.PostgreSql 10.0.0-rc.2 UPDATE: Oracle 10 rc2 is also published.
Hi @borisdj ,
I am currently testing the EFCore.BulkExtensions.PostgreSql/10.0.0-rc.2 with .NET 10 (EF Core 10).
When using the library via NuGet, I encounter the following exception during
await dbContext.BulkInsertAsync(source);
System.Collections.Generic.KeyNotFoundException: The given key '0..5' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
I suspected a version mismatch with the EF Core 10 internals. To verify this, I cloned the repository and referenced the EFCore.BulkExtensions.PostgreSql project directly in my solution (source code reference) instead of using the compiled DLL/NuGet package.
Result: The exact same code worked perfectly without any changes to the library source code. (both debug and relase mode)
It seems there is a binary incompatibility between the current nuget version and the latest .NET/EF Core 10 runtime, likely due to changes in EF Core's internal metadata structures.
Maybe, recompiling the library resolves the issue, idk.
Thanks for the great work!
Confirm that I've encountered an error in version 10.0.0-rc.2 of EFCore.BulkExtensions.PostgreSql when running on .NET 10 and call
await _appDbContext.BulkInsertAsync(newAccScores);
and got this error throw up
System.InvalidOperationException: Error updating subject score structure: The given key '0..13' was not present in the dictionary.
---> System.Collections.Generic.KeyNotFoundException: The given key '0..13' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at EFCore.BulkExtensions.SqlAdapters.PostgreSql.PostgreSqlAdapter.GetPropertyValue[T](DbContext context, TableInfo tableInfo, String propertyName, T entity)
at EFCore.BulkExtensions.SqlAdapters.PostgreSql.PostgreSqlAdapter.InsertAsync[T](BulkContext context, IEnumerable`1 entities, TableInfo tableInfo, Action`1 progress, Boolean isAsync, CancellationToken cancellationToken)
at EFCore.BulkExtensions.SqlAdapters.PostgreSql.PostgreSqlAdapter.InsertAsync[T](BulkContext context, IEnumerable`1 entities, TableInfo tableInfo, Action`1 progress, Boolean isAsync, CancellationToken cancellationToken)
at EFCore.BulkExtensions.SqlAdapters.PostgreSql.PostgreSqlAdapter.InsertAsync[T](BulkContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, Action`1 progress, CancellationToken cancellationToken)
It appears there is an incompatibility with the .NET 10 runtime for some. But keep working
Note: I've workaround by switched to the package to EFCore.BulkExtensions.Dotnet10 (10.0.0-rc.2.25502.107) by PanoramicData temporary workaround.
The ToString conversion is applied to a range and not the string span, which is wrong.
https://github.com/borisdj/EFCore.BulkExtensions/blob/207eca010caf46174214ae04209fdce22e7ddd22/EFCore.BulkExtensions.PostgreSql/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs#L215
This here is wrong:
foreach (var entry in propertyName.AsSpan().Split("."))
{
if (propertyValue == null)
{
return null;
}
if (fullPropertyName.Length > 0)
{
fullPropertyName += $"_{entry.ToString()}";
}
else
{
fullPropertyName = new string(entry.ToString());
}
propertyValue = tableInfo.FastPropertyDict[fullPropertyName].Get(propertyValue);
}
It should probably be:
foreach (var entry in propertyName.Split("."))
{
if (propertyValue == null)
{
return null;
}
if (fullPropertyName.Length > 0)
{
fullPropertyName += $"_{entry}";
}
else
{
fullPropertyName = entry;
}
propertyValue = tableInfo.FastPropertyDict[fullPropertyName].Get(propertyValue);
}