Good evening everyone.
I’m developing a application with MVVM, Fluent NHibernate, WPF on C#.Net, and we need to generate reports of some windows. I need to create a Report using a Crystal Reports tool. AFAIK, Crystal Reports only generate reports with DataSets. In siimple application, i could only generate a DataSet, build the report, and make it run. But how i could do to make NHibernate understant, or how to make it works, passing data with NHibernate, instead of creating a DataSet and make this Report to directly access the database? In a short way to ask: I want to use all data obtained with NHibernate to populate the Report.
Any help will be welcome!!!
Best Regards,
Gustavo
http://ayende.com/blog/2376/converting-an-object-collection-to-a-dataset
http://abombss.com/blog/2007/05/09/nhibernate-to-dataset/
Yours is not a new problem. Basically, the usual solution is to get the information from NHibernate as a collection of domain objects, and then manually build a DataTable using the properties of those objects.
You can also bolt a little vanilla ADO onto NHibernate. NHibernate ITransactions have an Enlist() method which basically allows you to associate a plain ol ADO DbCommand to the ADO DbTransaction way down in the bowels of NHibernate’s implementation, and execute it as you would if you weren’t using NHibernate, to get results in ADO.NET format. Here’s something I put into a Repository implementation, allowing me to call legacy stored procedures by name:
The DataReader can then be used to populate a DataTable/DataSet.
Some notes; the IUnitOfWork object you see is a token that links to a Session and its Transaction, and is used to control their scope and lifetime; you can modify this to use whatever session-handling mechanism you have (including creating a new Session from the SessionFactory just for this command, if you choose). You can also pass in “naked” SQL strings to execute; I typically avoid this (in fact, the names of the stored procs in the actual implementation are abstracted behind constant instances of a particular static type, similar to an enum).