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.
This worked for me , got a list of strings from procedure output cursor
you can just use 'System.String' or 'java.lang.String' as the property
if IBatis-3, just use below
Use auto result-mapping of IBatis. This is the solution in Java which you can easily map to C#. This is your sql map:
And then you can call it like this:
So you don't have to create a custom type with one property to do that.
My experience is the with Java version of iBATIS, but the solution should still work for the C# peeps out there.
Given a class
You can populate the list of strings or other simple types (classes without attributes, such as Integer, String, etc.) with the following two resultMaps
Hope this helps.
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.
iBatis seems to have no problem with that, just with mapping to a collection of strings.