Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SqlParameter to allow empty IEnumerable<SqlDataRecord>? #2971

Open
wjrogers opened this issue Nov 4, 2024 · 0 comments
Open

Change SqlParameter to allow empty IEnumerable<SqlDataRecord>? #2971

wjrogers opened this issue Nov 4, 2024 · 0 comments
Labels
💡 Enhancement Issues that are feature requests for the drivers we maintain. ✔️ Triage Done Issues that are triaged by dev team and are in investigation. 🙌 Up-for-Grabs Issues that are ready to be picked up for anyone interested. Please self-assign and remove the label ✨ Good first issue Issues that are simple enough for newcomers

Comments

@wjrogers
Copy link

wjrogers commented Nov 4, 2024

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:

// 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:

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?

@cheenamalhotra cheenamalhotra added the 🆕 Triage Needed For new issues, not triaged yet. label Nov 5, 2024
@samsharma2700 samsharma2700 added 💡 Enhancement Issues that are feature requests for the drivers we maintain. 🙌 Up-for-Grabs Issues that are ready to be picked up for anyone interested. Please self-assign and remove the label ✨ Good first issue Issues that are simple enough for newcomers ✔️ Triage Done Issues that are triaged by dev team and are in investigation. and removed 🆕 Triage Needed For new issues, not triaged yet. labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Enhancement Issues that are feature requests for the drivers we maintain. ✔️ Triage Done Issues that are triaged by dev team and are in investigation. 🙌 Up-for-Grabs Issues that are ready to be picked up for anyone interested. Please self-assign and remove the label ✨ Good first issue Issues that are simple enough for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants