你如何映射列表<串GT;在iBatis的? [英] How do you map a List<string> in iBatis?

查看:134
本文介绍了你如何映射列表<串GT;在iBatis的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一类

 公共SomeClass的
{
私有列表<串> _strings =新的List<串GT;();

公开的IEnumerable<串GT;字符串
{
{得到回报_strings; }
}
}



我怎么会做_strings映射<? / p>

我想这一点,但它抱怨名单类型处理器不被发现,它并没有抱怨,如果我映射它作为一个对象。

 <造成财产=_弦栏=值/> 



所以,我搜索谷歌和发现这个解决办法(最初用于Java的问题,不知道,如果它的猜想在C#中的工作)

 <造成财产=_弦resultMapping =someMapping.StringList/> 

< resultMap的ID =StringList的阶级=System.String>
<造成财产=列=值/>
< / resultMap的>

这至少可以让测试运行,并返回我的对象​​精细休息,我的名单有条目的正确数量,但他们都是空白的。



我认为这个问题是该财产属性为空,但我不知道什么猜想去那里。 (我也尝试使用价值,但也不能工作)。这似乎是它应该是简单了很多,我只是忽视的东西明显。



感谢。


解决方案

由于没有解决发现我只是我不是特别自豪的方法了。



我映射了一个类,有不是一个字符串值,没有其它的属性。

 公共类的StringValue 
{
公共字符串名称{ ;组; }
}

< resultMap的ID =StringList的阶级=的StringValue>
< result属性=姓名一栏=值/>
< / resultMap的>



iBatis的,似乎有没有问题,只是映射的字符串的集合。


I have a class like this

public SomeClass
{
   private List<string> _strings = new List<string>();

   public IEnumerable<string> Strings
   {
      {  get return _strings; }
   }
}

How would I do the mapping for _strings?

I tried this, but it complains about the List typehandler not being found, which it doesn't complain about if I mapped it as an object.

<result property="_strings" column="value" />

So I searched Google and found this workaround (originally for a Java issue, no idea if it's suppose to work in C#)

<result property="_strings" resultMapping="someMapping.StringList"/>

<resultMap id="StringList" class="System.String">
  <result property="" column="Value"/>
</resultMap>

This at least lets the test run, and it returns the rest of my object fine, and my list has the right number of entries, except they're all blank.

I think the problem is that the property attribute is blank, but I'm not sure whats suppose to go there. (I also tried using 'value', but that didn't work either). This seems like it should be a lot simpler and I'm just overlooking something obvious.

Thanks.

解决方案

Since no solution was found I just went with a method I'm not particularly proud of.

I mapped a class that had no other property other than a string value.

public class StringValue
{
    public String Name { get; set; }
}

<resultMap id="StringList" class="StringValue" >
  <result property="Name" column="Value"/>
</resultMap>

iBatis seems to have no problem with that, just with mapping to a collection of strings.

这篇关于你如何映射列表&LT;串GT;在iBatis的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆