zzzprojects / EntityFramework-Plus

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
https://entityframework-plus.net/
MIT License
2.25k stars 318 forks source link

Batch update does not work for keyless tables #557

Open joshfriend opened 4 years ago

joshfriend commented 4 years ago

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

JonathanMagnan commented 4 years ago

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 ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function