Database: Fix/database query activities failing parameters conversion from DBNull (71685)#445
Conversation
| } | ||
| else | ||
| { | ||
| currentParam.Set(asyncCodeActivityContext, null); |
There was a problem hiding this comment.
I would remove the condition on else
if there is nothing to set, I would not set null; (this is a business requirement)
for example if I have a in/out param with the initial value 100, then the procedures value for the param is DbNull.. do we want to set to zero the value in this case? or let it as it was? we can use default instead of null if needed
also null assignment wouldn't work if the type is a value type (eg. integer or bool);
eg.:
object o = null;
bool v = (bool)o;
|
Good fix — passing One edge case to consider: value types. If an Out/InOut parameter is The ADO.NET/Dapper/EF Core consensus for DBNull mapping is:
Suggested approach: if (param.Value.Value == DBNull.Value)
{
var argType = currentParam.ArgumentType;
if (!argType.IsValueType || Nullable.GetUnderlyingType(argType) != null)
{
currentParam.Set(asyncCodeActivityContext, null);
}
else
{
currentParam.Set(asyncCodeActivityContext, Activator.CreateInstance(argType));
}
}
else
{
currentParam.Set(asyncCodeActivityContext, param.Value.Value);
}Same change applies to both |
Fixed ExecuteQuery and ExecuteNonQuery throwing an exception when trying to convert the parameter of type DBNull returned by the query:
A value of type 'System.DBNull' cannot be set to the location with name 'Argument1' because it is a location of type 'System.String'https://uipath.atlassian.net/browse/STUD-71685