tags:

views:

66

answers:

2

I have a table with about 10.000 records (plus detail data in 11 tables). I want to display the data in a browsable form (1st, previous & next, last buttons).

I thought about retrieving all the records, putting the data into a collection of business objects and binding the form to the collection. Thinking about it, it came to my mind that it could take a while and could possibly result in a lot of memory being used ...

So maybe I should just retrieve the first record and get the next one when requested? What Do you think?

A: 

If the data is used frequently, but does not change often, you could consider caching it on the application level. If you retrieve the data on form level, a probably good compromise between speed and memory consumption would be to get e.g. 11 records (current, 5 previous and 5 next), and if the user goes past the retrieved records, get the next 5 again etc.

simon
+1  A: 

If you're not using an OR/M like nHibernate or iBatis, let me suggest that now. I use nHibernate - but I hear great things about iBatis. They have batching and lazy loading built in and configurable. Plus, the next time a situation like this arises, you'll have this functionality in minutes thanks to a pre-established flexible data access layer.

If you're not going to go the route of an OR/M, I'd suggest one-by-one fetching until performance becomes an issue - why complicate things unnecessarily upfront? If performance becomes an issue, then consider batch fetching and caching.

Travis Heseman
everybody suggests to do that. I dodged doing it all the time cuz it means throwing away months of work ...
MAD9
Understandable. One thing I've learned is evaluation of ROI when considering whether to throw work away or hold on to it. Sometimes throwing away "months" of work saves many more months in the long run of development and maintenance. One thing to consider: will a future "new developer" be more inclined to know or learn a well documented and widely adopted OR/M or your custom data access layer? Good luck with your considerations.
Travis Heseman
I have made a decision and threw my stuff away =)
MAD9
One thing I would do before taking a big step like this is learn the new technology. Many, dare I say most, folks with whom I've worked will jump on a tool like mice on cheese, but they'll never read the documentation and learn the technology. I recommend reading the docs BEFORE moving to a new technology. A good cup o' jo and an hour or two of hard reading before-hand will pay dividends.
Travis Heseman
Looking back I have to say moving to NHibernate was definitely the right decision. Nonetheless I thank you for your advice! I learned a lot writing the code I threw away, so it wasn't completely for the birds.In fact my project is 70% learning and 30% real business (I'm new to C#, only done VBA before)
MAD9