DbUpdateException can cause LINQPad to hang
Tested on v5.46 and v5.47
To reproduce get an instance of Microsoft.EntityFrameworkCore.DbContext
to throw a DbUpdateException
that contains an Entries
property whose Context
property has many DbSet<T>
properties referencing very large tables (in our case this precondition was met by using Microsoft.EntityFrameworkCore.SqlServer 3.1.18
and attempting to insert a row into a table with a trigger that returns fewer columns than EF is expecting, resulting in a DbUpdateException
wrapping an IndexOufOfRangeException
wrapping a null
).
LINQPad appears to hang as if waiting for the query, when actually the query has failed and LINQPad is spending a great deal of time walking the exception's object graph - when it encounters the first DbUpdateException.Entries[].Context
it finds there several DbSet<T>
properties that correspond to very large tables, and by consuming their enumerables causes a cascade of 'select' queries to be issued, each of which has no where clause and so would run for a very long time.
With LINQPad in this state I proceeded to kill each of the queries it thankfully runs one-by-one, and after I had killed one for each of the dbsets on our context, LINQPad printed out the exception's object graph:
I tried to reproduce on LINQPad v7.1.1 but it throws this exception just trying to initialize the DbContext:
(TypeInitializationException) The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception. (MissingMethodException) Method not found: 'System.Security.CodeAccessPermission System.Data.Common.DbProviderFactory.CreatePermission(System.Security.Permissions.PermissionState)'.
Comments
I'll add a fix to the next build. In the meantime, you can work around it by adding a static ToDump method to the My Extensions query:
This issue shouldn't manifest in LINQPad 7. It sounds you're using a very old version - have you tried LINQPad 7.6?
I had to change the workaround slightly but this works, thanks!
I downloaded v7.6.6 and haven't yet been able to get passed the MissingMethodException (at one point I was getting "Microsoft.Data.SqlClient is not supported on this platform" but I'm not sure if that's progress)
What was wrong with the workaround? I will be building something similar into LINQPad.
the classnames were actually something like "Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1[[SomeFully.Qualified.TypeName...."
got it working in v7.6.6 can confirm the hang doesn't happen there.
This error is still occurring in 7.6.6. The fix from gordy works though