Is there a way to access the columns in a Dapper FastExpando via string or index?

后端 未结 3 646
[愿得一人]
[愿得一人] 2020-12-29 04:36

I am pulling in a Dapper FastExpando object and want to be able to reference the column names dynamically at run time rather than at design/compile time. So I

3条回答
  •  清酒与你
    2020-12-29 05:37

    Regarding the portion of the title "or index?" - I needed to access results by index since the column names being returned changed sometimes, so you can use a variation of Sam Saffron's answer like this:

    var sql = "select 1, 'two'";
    var row = (IDictionary)connection.Query(sql).First();
    row.Values.ElementAt(0).IsEqualTo(1);
    row.Values.ElementAt(1).IsEqualTo("two");
    

提交回复
热议问题