Closed isaacabraham closed 2 years ago
Are you talking about the HydraReader
constructor?
If so you could just cast the IDataReader
:
https://github.com/JordanMarr/SqlHydra/blob/1dabec93fe9e0d8b8a06e3e900497e74e966edb5/src/SampleApp/DonaldExample.fs#L21
The problem is that the IDataReader
I'm using - Dapper's ExecuteReader
extension method on top of a SqlConnection
doesn't give back a SqlDataReader
underneath the IDataReader
.
Interesting... Apparently the Dapper crew wrapped it in an extra layer, so I had to do this:
let getProductsWithThumbnailDapper(conn: SqlConnection) = task {
use wrappedReader = conn.ExecuteReader("SELECT TOP 2 * FROM SalesLT.Product p WHERE ThumbNailPhoto IS NOT NULL")
use reader = (wrappedReader :?> IWrappedDataReader).Reader :?> SqlDataReader
let hydraReader = SalesLT.HydraReader(reader)
return [
while reader.Read() do
hydraReader.Product.Read()
]
}
Async version:
let getProductsWithThumbnailDapperAsync(conn: SqlConnection) = task {
use! wrappedReader = conn.ExecuteReaderAsync("SELECT TOP 2 * FROM SalesLT.Product p WHERE ThumbNailPhoto IS NOT NULL")
use reader = (unbox<IWrappedDataReader> wrappedReader).Reader :?> SqlDataReader
let hydra = SalesLT.HydraReader(reader)
return [
while wrappedReader.Read() do
hydra.Product.Read()
]
}
Added Dapper to samples.
Perfect, thanks.
Dapper returns an
IDataReader
on it's extension method on top of theSqlConnection
. Unfortunately, this does not contain theGetDateTimeOffset
member thatSqlDataReader
does, so the generated SqlHydra code does not work.Is there an alternative for the use of this member that would work with an
IDataReader
?