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

后端 未结 2 630
感动是毒
感动是毒 2021-02-13 05:27

I have a dynamic result from Dapper query that contains records like this:

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

I\'m

2条回答
  •  情歌与酒
    2021-02-13 06:21

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

    var data = (IDictionary)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]
    

提交回复
热议问题