1

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))"/>

2 Answers 2

2

Lazy properties are only supported from NHibernate 3 and up, so you need to upgrade if you want that property to be on your entity.

Another possiblity is to create an entity which is lazy-loaded and has just this single property on it (you could even map it to the same table).

I don't know if this is an issue to you, but you should also consider creating a view for that calculation which uses group by. This is important if you want to load not a single but many entities at the same time as group by usually performs mich better than a subselect.

Sign up to request clarification or add additional context in comments.

Comments

0

http://ayende.com/Blog/archive/2010/01/27/nhibernate-new-feature-lazy-properties.aspx

Looking at the date I don't think that made it into 2.1.2, since that was released in nov 2009.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.