I have a scenario where I need to return a
DataTable from a query using Dapper.
How do I return a
DataTable from a query using Dapper?
DataTable dt = connection.Query("SELECT * FROM table");
There will be no advantage whatsoever in using dapper for a scenario involving
DataSet. And in particular, your specific example (without any parameters etc) is so trivial (not meant negatively - simply objectively) that you might as well use
ExecuteReader directly, or use a
I am, however, open to exposing an API on dapper that exposes the
IDataReader API from dapper - you could feed that to any consumer you want,
DataTable included. But I really must question: what would be the point in performing this example via dapper? It might make more sense if you were at least using dapper to handle parameters (I'm damned pleased with how the parameter handling worked out, truth be told).
Huh? Dapper only provides extension methods over ADO.NET - so that you don't have to deal with DataTables and DataSets!
If DataTables and DataSets are what you want - you can still use vanilla ADO.NET - SqlDataAdapter (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx) will give you all the DataTables your heart desires :)