I'm using NHibernate 1.2 GA and I have a problem
My Order class has a few properties like this:
public virtual decimal Total
{
get {
decimal total = 0;
foreach (OrderItem item in OrderItems) {
total += item.Total;
}
total += ShippingCost;
total += Tax*total;
return total;
}
set { }
}
You can see that the Total property is calculated based on the OrderItems and other properties of the class. I'm coding the Total this way to avoid having to call a RecalculateTotal method any time a dependent orderItem or property changes.
The mapping for the property is:
<property name="Total" column="total" type="Decimal" not-null="true" />
I can get, insert, update and delete orders, but the problem is that when I get an order, even if I don't change it, it gets updated.
I think this is because of automatic dirty chechking.
The total is stored as decimal(8, 4) in a SQL Server 2005 DB. So when I create an order, if the Total was 1.353433, the value 1.3534 will be stored in the database.
When NHibernate loads the order, the Total returns 1.353433 but when NHibernate loaded the Total, it read 1.3534 from the database, so when the flushing happens, as the value does not match, it forces an update of the order.
Is there any way to avoid this update for my usage scenario?
|