Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
DataMapper 3.0
-
None
Description
To avoid creation of new Instance of the same object during an ibatis request, add the 'keys' attribute on resultMap tag to specify the properties identifiers
public class Order
{
public Account
...
}
<resultMap id="account-constructor-circular" keys="identifiant" class="Account" >
<constructor>
<argument argumentName="identifiant" column="Account_ID"/>
<argument argumentName="firstName" column="Account_FirstName"/>
<argument argumentName="lastName" column="Account_LastName"/>
</constructor>
</resultMap>
<resultMap id="order-result-circular" extends="base-order-result" class="Order">
<result property="Account" resultMapping="Account.account-constructor-circular"/>
</resultMap>
<select id="GetOrderWithAcccount" resultMap="order-result-circular" >
SELECT
*
FROM
Orders o
JOIN
Accounts a
ON
o.Account_Id = A.Account_Id
</select>
List<Order> list = (List<Order>)dataMapper.QueryForList<Order>("GetOrderWithAcccount", null);
Account account1 = list.Find(delegate(Order order)
{ return order.Id==1; }).Account;
Account account2 = list.Find(delegate(Order order)
).Account;
Assert.That(account1, Is.SameAs(account2));