kevinwarner wrote:
We are currently using NHibernate and having great success in our transactional management of data (working with one or two things at a time.) However, I would like to hear from others on how they might handle the following situations...
1. Displaying Web-Based Report
So far, I am not having any trouble with this. Our approach is to use custom paging and only retrieve up to 100 records to display on a page. So, I use a Criteria query to retreve the Student objects and then bind to a DataGrid. This seems like a reasonable approach. At least we have not had too many performance issues yet.
That works, but personally I prefer to return what I call reporting objects. NHibernate lets you specify just the fields you want and then place them in to a strongly typed class. That class just needs to take the fields in the constructor in the same way the HQL uses them. Create the class with the fields you want. Add a constructor taking the fields you want. Add an import to a mapping file, and then call the constructor with NEW MyReportingObject() in the HQL.
This should help with performance.
kevinwarner wrote:
2. Generating Excel File Report
This example is where I would like to get some other opinions. We have the same basic reporting capabilities, however, in this example, we do not want to limit the results to 100 at a time. We may need to generate an Excel document with ten thousand records and then allow the user to download that file. If I follow my same approach as above, using a Criteria query or even HQL to retrieve the Student objects, then I would have to loop through each one, generating the appropriate CSV/Excel record based on the data from the object.
I see a few possible issues with #2...
First, isn't retrieving that many objects going to put a strain on memory and also performance? Doesn't this approach load ten thousand Students into memory?
Second, doesn't looping through these ten thousand records also put a strain on the performance of the application?
Is there an efficient method to perform this operation with NHibernate? Or, should I be using ADO.Net directly to return a DataReader for example?
Finally, I have gotten used to having this wonderful NHibernate set of tools for nearly 100% of my data access layer. I have been implementing a domain driven design approach to my application. So, I am wanting to come up with a solution that can fit nicely within this approach.
I appreciate any suggestions or advice!
Kevin
Reference my above suggestion. Use the reporting objects. An easy (even if it is not the most efficient) way to generate excel documents from an ASP.NET page is to render the DataGrid to an excel file instead of the UI. Excel can read tables and will then show the data in a readable excel format which can be saved as a normal excel document. This is a little kludgy, but it is easy and free. There are numerous examples of how to do this on the web. This of course is just an option if you are not using a tool such as reporting services. Even so it is pretty handy to have the exact view the user sees on the page returned to them in an excel format.