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.27k stars 318 forks source link

EF CORE 8 and Pgsql 8: Parameter without name in synchronize & merge #787

Closed Belphemur closed 1 year ago

Belphemur commented 1 year ago

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

EntityFramework plus seems to create paramter without name and with null value. Wasn't the case in EF Core 7

2. Exception

If you are seeing an exception, include the full exception details (message and stack trace). Synchronize call:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Parameter '' cannot be null, DBNull.Value should be used instead.
   at Npgsql.ThrowHelper.ThrowInvalidOperationException(String message)
   at Npgsql.NpgsqlParameter.BindCore(Boolean allowNullReference)
   at Npgsql.NpgsqlParameter.Bind(DataFormat& format, Size& size)
   at Npgsql.NpgsqlBinaryImporter.Write[T](T value, NpgsqlParameter param, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlBinaryImporter.Write[T](T value, NpgsqlDbType npgsqlDbType)
   at InvokeStub_NpgsqlBinaryImporter.Write(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at .( , DbConnection , DbTransaction , Int32 )
   at .( )
   at .( )
   at .Execute(List`1 actions)
   at .(List`1 )
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.BulkOperations.BulkOperation.BulkSynchronize()
   at .BulkSynchronize[T](DbContext this, IEntityType entityType, IEnumerable`1 list, Action`1 options, Boolean forceSpecificTypeMapping)
   at .BulkSynchronize[T](DbContext this, IEnumerable`1 entities, Action`1 options)
   at DbContextExtensions.BulkSynchronize[T](DbContext this, IEnumerable`1 entities, Action`1 options)
   at DbContextExtensions.`1.()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at DbContextExtensions.BulkSynchronizeAsync[T](DbContext this, IEnumerable`1 entities, Action`1 options, CancellationToken cancellationToken)
   at AddictedProxy.Services.Provider.Shows.ShowRefresher.RefreshShowsAsync(CancellationToken token) in /src/AddictedProxy/Services/Provider/Shows/ShowRefresher.cs:line 57
   at AddictedProxy.Services.Provider.Shows.ShowRefresher.RefreshShowsAsync(CancellationToken token) in /src/AddictedProxy/Services/Provider/Shows/ShowRefresher.cs:line 57
   at AddictedProxy.Services.Provider.Shows.Jobs.RefreshAvailableShowsJob.ExecuteAsync(CancellationToken cancellationToken) in /src/AddictedProxy/Services/Provider/Shows/Jobs/RefreshAvailableShowsJob.cs:line 28
   at InvokeStub_TaskAwaiter.GetResult(Object, Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Merge call:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Parameter '' cannot be null, DBNull.Value should be used instead.
   at Npgsql.ThrowHelper.ThrowInvalidOperationException(String message)
   at Npgsql.NpgsqlParameter.BindCore(Boolean allowNullReference)
   at Npgsql.NpgsqlParameter.Bind(DataFormat& format, Size& size)
   at Npgsql.NpgsqlBinaryImporter.Write[T](T value, NpgsqlParameter param, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlBinaryImporter.Write[T](T value, NpgsqlDbType npgsqlDbType)
   at InvokeStub_NpgsqlBinaryImporter.Write(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at .( , DbConnection , DbTransaction , Int32 )
   at .( )
   at .( )
   at .Execute(List`1 actions)
   at .(List`1 )
   at Z.BulkOperations.BulkOperation.Execute()
   at Z.BulkOperations.BulkOperation.BulkMerge()
   at .BulkMerge[T](DbContext this, IEntityType entityType, IEnumerable`1 list, Action`1 options, SavingSelector savingSelector, Boolean forceSpecificTypeMapping)
   at Z.EntityFramework.Extensions.PublicInternalBulkOperationManager.BulkMergeCastWithSavingSelector[T,OldT](BulkOperation`1 this, DbContext context, IEntityType entityType, List`1 list, SavingSelector savingSelector, Boolean forceSpecificTypeMapping)
   at InvokeStub_PublicInternalBulkOperationManager.BulkMergeCastWithSavingSelector(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at .BulkMerge[T](DbContext this, IEntityType entityType, IEnumerable`1 list, Action`1 options, SavingSelector savingSelector, Boolean forceSpecificTypeMapping)
   at .[](DbContext , SavingSelector , Action`1 )
   at .[](DbContext ,  , BulkOperationActionType , Action`1 )
   at .BulkMerge[T](DbContext this, IEnumerable`1 entities, Action`1 options, Boolean isBulkSaveChanges)
   at DbContextExtensions.BulkMerge[T](DbContext this, IEnumerable`1 entities, Action`1 options)
   at DbContextExtensions.`1.()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at DbContextExtensions.BulkMergeAsync[T](DbContext this, IEnumerable`1 entities, Action`1 options, CancellationToken cancellationToken)
   at AddictedProxy.Database.Repositories.Shows.EpisodeRepository.<>c__DisplayClass3_0.<<UpsertEpisodes>b__0>d.MoveNext() in /src/AddictedProxy.Database/Repositories/Shows/EpisodeRepository.cs:line 39
--- End of stack trace from previous location ---
   at AddictedProxy.Tools.Database.Transaction.TransactionManager`1.<>c__DisplayClass3_0.<<WrapInTransactionAsync>b__0>d.MoveNext() in /src/AddictedProxy.Tools.Database/Transaction/TransactionManager.cs:line 27
--- End of stack trace from previous location ---
   at AddictedProxy.Tools.Database.Transaction.TransactionManager`1.<>c__DisplayClass3_0.<<WrapInTransactionAsync>b__0>d.MoveNext() in /src/AddictedProxy.Tools.Database/Transaction/TransactionManager.cs:line 28
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c.<<ExecuteAsync>b__3_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at AddictedProxy.Tools.Database.Transaction.TransactionManager`1.WrapInTransactionAsync(Func`1 dbAction, CancellationToken token) in /src/AddictedProxy.Tools.Database/Transaction/TransactionManager.cs:line 24
   at AddictedProxy.Database.Repositories.Shows.EpisodeRepository.UpsertEpisodes(IEnumerable`1 episodes, CancellationToken token) in /src/AddictedProxy.Database/Repositories/Shows/EpisodeRepository.cs:line 30
   at AddictedProxy.Services.Provider.Episodes.EpisodeRefresher.RefreshEpisodesAsync(TvShow show, Season season, CancellationToken token) in /src/AddictedProxy/Services/Provider/Episodes/EpisodeRefresher.cs:line 86
   at AddictedProxy.Services.Provider.Episodes.EpisodeRefresher.RefreshEpisodesAsync(TvShow show, Season season, CancellationToken token) in /src/AddictedProxy/Services/Provider/Episodes/EpisodeRefresher.cs:line 89
   at AddictedProxy.Services.Provider.Episodes.EpisodeRefresher.GetRefreshEpisodeAsync(TvShow show, Season season, Int32 episodeNumber, CancellationToken token) in /src/AddictedProxy/Services/Provider/Episodes/EpisodeRefresher.cs:line 54
   at AddictedProxy.Services.Provider.Subtitle.Jobs.FetchSubtitlesJob.ExecuteAsync(JobData data, CancellationToken cancellationToken) in /src/AddictedProxy/Services/Provider/Subtitle/Jobs/FetchSubtitlesJob.cs:line 91
   at InvokeStub_TaskAwaiter.GetResult(Object, Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

3. Fiddle or Project

Here the code line used to make the synchronize call: https://github.com/Belphemur/AddictedProxy/blob/dev/AddictedProxy.Database/Repositories/Shows/TvShowRepository.cs#L41

I have the same issue with BulkMerge: https://github.com/Belphemur/AddictedProxy/blob/dev/AddictedProxy.Database/Repositories/Shows/EpisodeRepository.cs#L28

Otherwise, make sure to include as much information as possible to help our team to reproduce the issue.

4. Any further technical details

Add any relevant detail can help us.

Further technical details

Belphemur commented 1 year ago

Wrong project, sorry for the notification. Moved to: https://github.com/zzzprojects/EntityFramework-Extensions/issues/558