In my product entity i have the following property. It works correctly and returns back the number of stock available. Looking at my profiler i can see that this statement is called everytime i call the product entity which is causing performance issues. Is there a way i can only call this property when needed. I've added 'lazy=true' but it is still called everytime. I'm using nhibernate 2. I'd prefer not to upgrade if poss.
<property name="StockAvailable" lazy="true" type="Int32" formula="(SELECT Stock - isnull((select Sum(oi.Quantity) from OrderItems oi inner join Orders o on oi.OrderId = o.Id where (oi.OrderItemStatusId = 0 or oi.OrderItemStatusId = 1) and o.OrderStatus = 3 and oi.ProductId = Id), 0))"/>