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.
At least in iBATIS3 for Java your above could just use a resultMap like:
The following is my experience with Java version of IBatis (version 2.3.4). My scenario was I wanted Ibatis to return me a map of keys and values for a given list of parameters. Done using Ibatis queryForMap method to return a map where the key is an Object and the values are a collection of Objects (this example Key is a Wrapper while the values are a list of Wrapper Longs).
Create a placeholder (with the getters/setters) to hold the data when the query executes.
Ibatis resultmap definitions
My initial troubles was getting the alias' right and the groupBy syntax on the parent map. Having the groupBy will get Ibatis to get the same object for the elementId to populate the children. One instance without the groupBy I found that for each key the previous child added to the list was replaced by the latest child as a new list was initialized (note I have not had a peep at the internals of Ibatis yet as I write this example). The placeholders alias must match the parent and child's resultMap. Ibatis 3 seems to have better syntax to define and handle a scenario as above.