-
Notifications
You must be signed in to change notification settings - Fork 315
Description
At the beginning of the GetActualFieldsAndProperties
branch for IEnumerable<SqlDataRecord>
, this comment suggests it will set the value to null
when the enumerable is empty:
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs
Lines 1291 to 1292 in 9d5ca32
// no need for fields if there's no rows or no columns -- we'll be sending a null instance anyway. | |
if (enumerator.MoveNext()) |
However, at the end, it throws an exception:
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs
Lines 1413 to 1416 in 9d5ca32
else | |
{ | |
throw SQL.IEnumerableOfSqlDataRecordHasNoRows(); | |
} |
System.ArgumentException: There are no records in the SqlDataRecord enumeration. To send a table-valued parameter with no rows, use a null reference for the value instead.
This means I have to check for an empty IEnumerable<SqlDataRecord>
before setting SqlParameter.Value
, which means I have to materialize and/or enumerate the source. For efficiency, I would like to avoid that. Considering SqlParameter
is already peeking at the enumeration to initialize the metadata, could it be changed to handle an empty enumerable the same as the value null
?