EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Batch Operations (Update/Delete) fails with "Specified argument was out of the range of valid values" and are very slow

Open stomasovic opened this issue 4 months ago • 3 comments

Migrating EntityFramework.Extended library to a modern implementation and successor Z.EntityFramework.Plus.EF6 library, should be quite simple task. Changing few using directives, and changing some return parameters of methods for Future Queries, minor tweaks and all should be fine, right? Estimation was to upgrade it in a day, maybe two.

Well, it was not that easy. I was mostly afraid of complex Future queries we have, and that was mostly fine. But when moved to migrate Batch Operations, which should be simplest part of the migration, it failed. Details of the errors:

Message:
Specified argument was out of the range of valid values.
Parameter name: index

Stack Trace:
System.ArgumentOutOfRangeException
Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
...
DbContextExtensions.GetModel(DbContext this)
BatchDelete.Execute[T](IQueryable`1 query)

The same error is for Update. Those three dots (...) are some obfuscated calls, and can not write meaningful stack trace.

Along with errors, it is also very slow to execute my tests. Tests using EntityFramework.Extended are running half a minute, but tests using Z.EnittyFramework.Plus.EF6 were running 3 to 6 minutes, which is more then 10 times slower and I feel the slowness.

EntityFramework.Extended worked fine for those Batch Operations, but new library failed. I tried on several DbContext within app, and it is the same issue on most of the DbContexts (one small context is working). I tried different versions of library, 9.x, 8.x, 7.x, even 1.x, same error always.

App is using DbInterceptors and Wrap DbSet calls, but even if remove wrapping DbContext.Set and interceptors, same error happened. Any guideline how to debug and fix the issue.

stomasovic avatar Aug 29 '25 15:08 stomasovic

Seems that Future queries have issues as well. Tests were running fine, but some failed with:

Message: 
Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]

Stack Trace: 
System.Exception
PublicInternalExtensions.GetObjectQuery[T](IQueryable`1 query)
QueryDeferredExtensions.DeferredAny[TSource](IQueryable`1 source)

Will continue investigating and let you know the results.

stomasovic avatar Aug 29 '25 21:08 stomasovic

Hello @stomasovic ,

Do you think you could create a runnable project with the issue? It doesn’t need to be your project, just a new solution with the minimum code to reproduce the issue will be the best.

In most case, the migration is very easy. There is definitely something in your context/object query we do not support yet looking at your both stack trace but we cannot know exactly what without this runnable project.

You can send it in private here if you need: [email protected]

Best Regards,

Jon

JonathanMagnan avatar Aug 30 '25 14:08 JonathanMagnan

Hello @stomasovic

Unfortunately, since we didn't hear from you I will close this issue.

As previously mentioned, we need a runnable project to be able to assist you.

We will reopen the issue if a project is received.

Feel free to contact us for questions, issues or feedback.

Best Regards,

Jon

JonathanMagnan avatar Sep 11 '25 13:09 JonathanMagnan