有没有办法通过字符串或索引访问Dapper FastExpando中的列? [英] Is there a way to access the columns in a Dapper FastExpando via string or index?
本文介绍了有没有办法通过字符串或索引访问Dapper FastExpando中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在拉一个 Dapper FastExpando
对象,并希望能够在运行时而不是在设计/编译时动态引用列名。所以我想要能够执行以下操作:
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 want to be able to do the following:
var testdata = conn.Query("select * from Ride Where RiderNum = 21457");
我想要执行以下操作:
foreach( var row in testdata) {
var Value = row["PropertyA"];
}
我明白我可以做:
var Value = row.PropertyA;
但我不能这样做,因为我将需要的财产的名称赢得'直到运行时才知道。
but I can't do that since the name of the property i'm going to need won't be known until runtime.
这个SO问题不起作用。我仍然得到相同的目标调用
异常。所以...
The answer from this SO Question doesn't work. I still get the same Target Invocation
exception. So...
有没有办法用Dapper FastExpando做什么?
推荐答案
当然,这实际上比这更容易:
Sure, it is actually way easier than that:
var sql = "select 1 A, 'two' B";
var row = (IDictionary<string, object>)connection.Query(sql).First();
row["A"].IsEqualTo(1);
row["B"].IsEqualTo("two");
这篇关于有没有办法通过字符串或索引访问Dapper FastExpando中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文