what's the alternative to readonlycollection when using lazy="extra"?

Posted by Kunjan on Stack Overflow See other posts from Stack Overflow or by Kunjan
Published on 2010-06-18T07:49:39Z Indexed on 2010/06/18 7:53 UTC
Read the original article Hit count: 541

I am trying to use lazy="extra" for the child collection of Trades I have on my Client object. The trades is an Iset<Trade> Trades, exposed as ReadOnlyCollection<Trade> because I do not want anyone to modify the collection directly. As a result, I have added AddTrade and RemoveTrade methods.

Now I have a Client Search page where I need to show the Trade Count. and on the Client details page I have a tab where I need to show all the trades for the Client in paged gridview.

What I want to achieve is, for the search when I say on the client object as client.Trades.Count, nHibernate should only fire a select count(*) query. Hence I am using lazy="extra". But because I am using a ReadOnlyCollection, nHibernate fires a count query & a separate query to load the child collection trades completely. Also, I cannot include the Trades in my initial search request as this would disturb the paging because a counterparty can have n trades which would result in n rows, when I am searching clients only. So the child collections have to be loaded lazily.

The second problem is that on the client details page --> Trades grid view, I have enabled paging for performance reasons. But by nature nHibernate loads the entire collection of trades as the user goes from one page to another. Ideally I want to control this by getting only trades specific to the page the user is on. How can I achieve this?

I came across this very good article.

http://stackoverflow.com/questions/876976/implementing-ipagedlistt-on-my-models-using-nhibernate

But I am not sure if this will work for me, as lazy=extra currently doesnt work as expected with the ReadOnlyCollection. So, if I went ahead and implemented the solution this way and further enhanced it by making the List/Set Immutable, will lazy=extra give me the same problem as with ReadOnlyCollections?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about paging