Change SqlParameter to allow empty IEnumerable<SqlDataRecord>?
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
At the beginning of the `GetActualFieldsAndProperties` branch for `IEnumerable`, this comment suggests it will set the value to `null` when the enumerable is empty:
https://github.com/dotnet/SqlClient/blob/9d5ca32e666b3da1cc27b4ab145367308998b147/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs#L1291-L1292
However, at the end, it throws an exception:
https://github.com/dotnet/SqlClient/blob/9d5ca32e666b3da1cc27b4ab145367308998b147/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs#L1413-L1416
> 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` 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`?
Contributor guide
Assessment
This issue has not been assessed yet.