Can I get the field structure from a Dapper query?

c# dapper

Question

I've been looking through the source code, but there is a fair amount going on for such a small ORM. Is there any way to retrieve the field structure of a query returned by Dapper after calling .Query()? Essentially I need the same data as returned by a DataReader when you call GetSchemaTable().

Popular Answer

This can be done as follows:

Fetch the reader using either of the following calls:

IDataReader dr = _connection.ExecuteReader(sql)

or

IDataReader dr = _connection.GetStream(sql)

Now you can call dr.GetSchemaTable() to get the relevant schema DataTable In fact you may typecast the same to relevant DbDataReader type like SqlDataReader or OracleDataReaderin case you want to utilize an overload of a GetSchemaTable()



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why