Hello,
The problem:
I have a class like this:
public class Item
{
private int _id;
private HashTable _desc;
public Item()
{
_id = 0;
_desc = new HashTable();
}
public int Id
{
get{return _id;}
set{_id=value;}
}
//this represents a set of key,value of localized strings, for instance
// "it-IT", "Buongiorno"
// "en-US", "Good Morning"
// "fr-FR", "Bonjour"
// an so on
public HashTable Desc
{
get{return _desc;}
set{_desc = value; }
}
}
//client code example
Item item = _mapper.QueryForObject("SelectItem", itemid);
string LCID = "en-US"; //actually this is parameterezid elsewhere.
//this is what I would have
string englishDescription = (string)item.Desc[LCID];
//even better: a KeyPairValue<string,string> for property Desc, which //would
lead to //drop the explicit string cast
string englishDescription = item.Desc[LCID];
Database Tables examples
table ITEMS
itemId
partNumber
streetPrice
etc etc
PK(intemID)
table ITEMDESC
itemId //foreign key to column itemId of table ITEMS
LCID
Description
PK(itemId, LCID)
Now, how could this be done with iBatis? It would be nice to have a mapping
like this:
<resultMap id="ItemResul" class="Item">
<result property="Id" column="Id" type="int" dbType="Int"/>
<result property="Desc" column="Id" select="SelectDescLCID"
lazyload="false"/>
</resultMap>
<select id="SelectItem" parameterClass="string" resultMap="ItemResul">
SELECT intemId AS Id, partNumber AS PartNumber
FROM items
WHERE itemId=#value#
</select>
<select id="SelectDescLCID" parameterClass="string" resultmap="?????">
SELECT LCID as Key, Descr as Value
FROM ITEMDESC
WHERE itemId=#value#
</select>
Is there a way to achive this?
Thank you
Cheers,
Andrea