Skip to content

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

@wjrogers

Description

@wjrogers

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement 💡Issues that are feature requests for the drivers we maintain.Good First Issue ✨Issues that are simple enough for newcomersTriage 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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions