Skip to content

Commit 0cb7f54

Browse files
committed
Map null to DBNull.Value in QueryFile
1 parent 3eb09f4 commit 0cb7f54

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

src/Dibix.Http.Server/Runtime/HttpParameterResolver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ private static Expression CollectSourcePropertyValue(IHttpActionDescriptor actio
579579
if (nullCheckTargets.Any())
580580
{
581581
Expression test = nullCheckTargets.Select(x => Expression.NotEqual(x, Expression.Constant(null))).Aggregate(Expression.AndAlso/* Short-circuit behavior like && in C# */);
582+
// DBNull.Value is used when the default value of a method parameter is not set
583+
// Slightly confusing...
582584
bool hasDefaultValue = parameter.DefaultValue != DBNull.Value && parameter.DefaultValue != null;
583585
Expression fallbackValue = hasDefaultValue ? Expression.Constant(parameter.DefaultValue) : Expression.Default(parameter.ParameterType);
584586
value = EnsureCorrectType(parameter.InternalParameterName, value, parameter.ParameterType, actionParameter);

src/Dibix/Access/DbCommandParameterCollector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public override void VisitInputParameter(string name, DbType dataType, object va
4545
throw new ArgumentOutOfRangeException(nameof(customInputType), customInputType, null);
4646
}
4747

48+
parameter.Value ??= DBNull.Value;
4849
_command.Parameters.Add(parameter);
4950
}
5051

0 commit comments

Comments
 (0)