Allow TVPs to be populated via asynchronous data sources & add a new field to SqlDbType
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
### Is your feature request related to a problem? Please describe.
Currently when you use IDataReader/DbDataReader as a source for a tvp parameter, it will always call the `Read()` method to consume rows.
In addition, only `IEnumerable` can be used as a source, not `IAsyncEnumerable`.
I think as a solution it would be beneficial to add a new SqlDbType, `StructuredAsync`, which would allow using an asynchronous way of populating a structured table valued parameter.
### Describe the solution you'd like
usage would be like so:
```cs
IAsyncEnumerable asyncRecords = GetAsyncRecords();
var paramA = new SqlParameter("@tvp", asyncRecords){
SqlDbType = SqlDbType.StructuredAsync,
TypeName = "dbo.tvp"
};
IDataReader asyncReader = GetAsyncReader();
var paramB = new SqlParameter("@tvp2", asyncReader){
SqlDbType = SqlDbType.StructuredAsync,
TypeName = "dbo.tvp"
};
```
### Describe alternatives you've considered
As an alternative, we could always call `ReadAsync(CancellationToken)`, however, this may regress scenarios where the reader is entirely synchronous and no async operations are needed.
Another approach could be add a boolean property in `SqlParameter` like `ReadMode`, but I feel like there are too many constructors and mutable properties on a `SqlParameter` already that is already incredibly difficult to find the options you neccessarily care about.
Contributor guide
Assessment
This issue has not been assessed yet.