SqlDataReader.GetFieldValue{,Async}() should work for Stream and TextReader
See original GitHub issueFollowing #30958, where @Wraith2 added the ability to retrieve an XmlReader via SqlDataReader.GetFieldValue()
and its async counterpart, we should do the same for Stream and TextReader. These can already be retrieved via GetStream()
and GetTextReader()
respectively.
The main motivation behind this would be to allow getting Reader/TextReader asynchronously without introducing new GetReaderAsync()
and GetTextReaderAsync()
methods. See https://github.com/dotnet/corefx/issues/35012#issuecomment-484440830 and below for previous discussion.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (7 by maintainers)
Top Results From Across the Web
SqlDataReader.GetFieldValueAsync<T>(Int32, ...
Asynchronously gets the value of the specified column as a type. GetFieldValue<T>(Int32) is the synchronous version of this method.
Read more >Access TextReader as a Stream
You can obtain a Stream through the use of the StreamReader class. StreamReader is a subclass of TextReader so you can easily access...
Read more >Introducing .NET 4.5
For detailed information about how to locate your book's source code, go to www.apress.com/source- code. Page 4. For Belinda and Mum, a book...
Read more >C# And dotNET Core 1.0 - StudyLib
In particular, you will learn how to declare and work with variables of different types. Chapter 3, Controlling the Flow, Converting Types, and...
Read more >ADO.NET Retrieving and Modifying Data - Sideway
Open() method passes the parsed connection parameters to the data source. ... in the SqlDataReader classes in order to get Stream, XmlReader, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@roji i’ve got this working on netcore but because of the different netcore and netfx codebases it’s more difficult to get it working on netfx. Since this would primarily be useful from EF and as far as a know modern EF only works on core or net5 onwards is there a need to implement on netfx immediately? It will eventually be implemented through the merging of the codebases.
@bgrainger has pointed out in one of the linked issues elsewhere that there is some slightly unexpected (but deliberate) behaviour when using the current sync stream methods,
GetStream
,GetTextReader
andGetXmlReader
all handle database NULL values by detecting it and returning an empty stream. Other methods of accessing the same fields will detect null and throw an appropriate exception.Should
GetFieldValue(Async)<T>
for stream types emulate the current behaviour of returning a constructed empty stream or should they throw null as GetString or GetBytes would do?I think it is up to the developer to ensure that their queries return sensible data and that if null can be present in the return from a query it should be explicitly handled by the consumer and not hidden by the ADO library. I’m in favour of throwing an exception if a stream over null data is requested through
GetFieldValue(Async)