Dapper: How to get value from DapperRow if column name is "count(*)"?

Suppose Your Data as below

var Details={DapperRow, billing_currency_code = 'USD', count(*) = '6'}

as The columns is coming dynamically

var firstRow= Details.FirstOrDefault();

To get the heading columns of the data

var Heading= ((IDictionary<string, object>)firstRow).Keys.ToArray();

To get the value of the data by using key

var details = ((IDictionary<string, object>)firstRow);
var vallues= details[Heading[0]];

If the column name genuinely is "count(*)", then you can cast the row to a dictionary:

var data = (IDictionary<string,object>)row;
object value = data["count(*)"];

For that to work (at least, in SQL Server), your query would need to be something like:

select count(*) as [count(*)]

However, in most cases the column doesn't have a name, in which case: fix your query ;p

Actually, I'd probably say fix your query anyway; the following would be much easier to work with:

select count(*) as [Count]

Tags:

Dapper