Setting DBNull.Value for null values
This commit is contained in:
@@ -663,7 +663,7 @@ public static partial class ExtensionMethods
|
||||
public static SqliteCommand SetParameterValues(this SqliteCommand self, Dictionary<string, object?> values)
|
||||
{
|
||||
foreach (var kvp in values)
|
||||
self.Parameters[kvp.Key].Value = kvp.Value;
|
||||
self.Parameters[kvp.Key].Value = kvp.Value ?? DBNull.Value;
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -753,7 +753,7 @@ public static partial class ExtensionMethods
|
||||
where T : IDbCommand
|
||||
{
|
||||
foreach (var kvp in values)
|
||||
((IDataParameter)self.Parameters[kvp.Key]!).Value = kvp.Value;
|
||||
((IDataParameter)self.Parameters[kvp.Key]!).Value = kvp.Value ?? DBNull.Value;
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -772,21 +772,7 @@ public static partial class ExtensionMethods
|
||||
if (value is not null && value is System.Collections.IEnumerable && value is not string)
|
||||
throw new ArgumentException($"Cannot set parameter '{name}' to an array or enumerable type, as the SQLite bindings does not support it.", nameof(value));
|
||||
#endif
|
||||
((IDataParameter)self.Parameters[name]!).Value = value;
|
||||
return self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the transaction for the command.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the command</typeparam>
|
||||
/// <param name="self">The command to set the transaction for</param>
|
||||
/// <param name="transaction">The transaction to set for the command</param>
|
||||
/// <returns>The command with the transaction set</returns>
|
||||
public static T SetTransaction<T>(this T self, IDbTransaction? transaction)
|
||||
where T : IDbCommand
|
||||
{
|
||||
self.Transaction = transaction;
|
||||
((IDataParameter)self.Parameters[name]!).Value = value ?? DBNull.Value;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user