【问题标题】:Mapping to Dictionary with iBATIS使用 iBATIS 映射到字典
【发布时间】:2010-09-12 02:28:06
【问题描述】:

给定一个简单的语句,例如:

<statement id="SelectProducts" resultMap="???">
  SELECT * FROM Products
</statement>

是否可以获得一个字典对象列表,其中键是列名? 即。

var list = Mapper.QueryForList<IDictionary<string,string>>("SelectProducts", null);

IDictionary<string, string> dict = list[0];
// dict["id"] == "1"
// dict["name"] == "Some Product Name"
// dict["price"] == "$9.99"
// etc.

我想概括查询结果以处理任意数量的列/列名,而不映射到某个类的特定属性。

我意识到这里的示例会失败,因为结果集可能有重复(或空)的列名。我考虑过一个包含键值对索引列表的结果类。这里的关键是将列信息保留在某处。

【问题讨论】:

    标签: .net ibatis datamapper


    【解决方案1】:

    您可以通过在 resultMap 配置中将 class 属性设置为 HashTable 来做到这一点。更多详情请见here

    【讨论】:

      猜你喜欢
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多