Batch update does not work for keyless tables
Description
Attempting to call .Update() on a query for a table with .HasNoKey() set on its model builder throws an exception here.
I have a keyless table for holding app config values that has only one row. I would like to run a statement like:
UPDATE "Configuration" SET "SomeConfigValue" = 123;
I've tried several variations of EF queries:
await _context.Configuration
.UpdateAsync(c => new Configuration { SomeConfigValue = 9999 });
await _context.Configuration.Where(x => true)
.UpdateAsync(c => new Configuration { SomeConfigValue = 9999 });
Exception
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Z.EntityFramework.Plus.BatchUpdate.CreateCommand(IQueryable query, IEntityType entity, List`1 values)
at Z.EntityFramework.Plus.BatchUpdate.Execute[T](IQueryable`1 query, Expression`1 updateFactory)
at Z.EntityFramework.Plus.BatchUpdateExtensions.Update[T](IQueryable`1 query, Expression`1 updateFactory, Action`1 batchUpdateBuilder)
at Z.EntityFramework.Plus.BatchUpdateExtensions.<>c__DisplayClass2_0`1.<UpdateAsync>b__0()
Further technical details
- EF version: EF Core 3.1
- EF Plus version: 3.0.24
- Database Provider: Postgres
Thank you for reporting,
We are supposed to review this feature this month, so we will certainly look at it very soon.
Best Regards,
Jonathan
Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework Extensions • Entity Framework Classic • Bulk Operations • Dapper Plus
Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval Function • SQL Eval Function