iBatisNet 的复杂类型属性 (即自定义类型的属性)
复杂类型用以表示在数据库中相互关系为一对一,一对多的数据. 对于一对多的数据关系,拥有复杂类型属性的类作为"多"的一方,而复杂属性本身则作为"一"的一方.
考虑下面的例子:
<resultMap id="GetProduct_Result" class="Product">
<result property="Id" column="Id"/>
<result property="Description" column="Description"/>
<result property="Category" column="CategoryId" select="GetCategory"/>
</resultMap>
<resultMap id="GetCategory_Result" class="Category">
<result property="Id" column="Id"/>
<result property="Description" column="Description"/>
</resultMap>
<statement id="GetProduct" parameterClass="int" resultMap="GetProduct_Result">
select * from Product where Id = #value#
</statement>
<statement id="GetCategory" parameterClass="int" resultMap="GetCategory_Result">
select * from Category where Id = #value#
</statement>
上面的例子中,Product对象拥有一个类型为Category的Category属性. 因为Category是复杂类型(用户定义的类型),通过将Category属性值和另一个mapped statement联系起来,为SQL Map引擎如何给它赋值提供了足够的信息. 通过执行"GetProduct","GetProduct_Result" Result Map使用CategoryId字段的值去调用"GetCategory". "GetCategory_Result" Result Map将初始化一个Category对象并赋值给它. 然后整个Category对象将赋值给Product的Category属性.
浙公网安备 33010602011771号