artiomchi / FlexLabs.Upsert

FlexLabs.Upsert is a library that brings UPSERT functionality to common database providers for Entity Framework in their respective native SQL syntax
MIT License
511 stars 81 forks source link

Exception due to null constant in expression + Fix. #130

Open timaiv opened 1 year ago

timaiv commented 1 year ago

Version 6.0.1 Exception message: The parameterized query '(@p0 bigint,@p1 datetime2(7),@p2 int,@p3 int,@p4 varchar(100),@p' expects the parameter '@p5', which was not supplied. How to reproduce:

.WhenMatched((dbTx, upTx) => new TransactionInfo()
                    {
                        SenderId = dbTx.SenderId == null ? upTx.SenderId : dbTx.SenderId
                    })

Fix: In PrepareDbCommandArgument change dbParameter.Value = constantValue.Value to dbParameter.Value = constantValue.Value ?? DBNull.Value Microsoft does same in CreateParameter (parameter.Value = value ?? DBNull.Value;)

andznui commented 7 months ago

I'm seeing the same issue. Looks like there is a proposed fix in the comment already. is there an ETA for the fix to get in @artiomchi ? @timaiv is there a workaround meanwhile?

andznui commented 7 months ago

actually, for the example in the issue a simple workaround is to use the coalesce operator.

.WhenMatched((dbTx, upTx) => new TransactionInfo()
                    {
                        SenderId = dbTx.SenderId ?? upTx.SenderId
                    })

Works for my use-case too.

hertznsk commented 1 month ago

160 works correctly for us. Is it possible to consider including it in the next version? @artiomchi