According to the Dapper documentation, you can get a dynamic list from dapper using the following code:
var rows = connection.Query("select 1 A, 2 B union all select 3, 4"); ((int)rows[0].A) .IsEqualTo(1); ((int)rows[0].B) .IsEqualTo(2); ((int)rows[1].A) .IsEqualTo(3); ((int)rows[1].B) .IsEqualTo(4);
What is the use of dynamic if you need to know the field names and data types of the fields. If I have:
var result = Db.Query("Select * from Data.Tables");
I want to do the following: Get a list of returned field names and data types.
Loop through it using the field names and get the data in the following ways:
result.Fields ["Id", "Description"] result[0].values [1, "This is the description"]
That would allow me to get
result[0].["Id"].Value
which will give results 1 and will, for example, be of type Int 32
result[0].["Id"].Type --- what datattype is the value returned result[0].["Description"]
which will produce the results of "This Description" and will be of type string.
I see that there is a results [0] .table file that has a dapperrow object with an array of field names, and there is also a result.values ββfile that is an object [2] with values ββin it, but it cannot be accessed. If I add a clock to the column name, I can get the identifier. Automatically created watches:
(new System.Collections.Generic.Mscorlib_CollectionDebugView<Dapper.SqlMapper.DapperRow>(result as System.Collections.Generic.List<Dapper.SqlMapper.DapperRow>)).Items[0].table.FieldNames[0] "Id" string
So I should be able to get the result [0] .Items [0] .table.FieldNames [0] and return "Id".