I'm new in NHibernate world and I'm starting to build a simple C# Windows Form Application that imports some XLS files into a DB (SQL2008), elaborates data and than exports a CSV file. I've tried to search some examples to how use and manage NHibernate session; some of them are useful for Web Application. I've seen that in MVC Application the NHibernate session is created on Application Start, but I can't understand when I must create the NHibernate session into a Windows Form Application.
Anyone can help me? Thank you!
Per the feedback I'll suggest that you look into using SSIS for this kind of work. Besides being designed for ETL processes like these SSIS can also be re-executed as needed and there's no need for custom code at all. Though if you want, it's not hard to write .NET code run SSIS packages as necessary. Here's an example. Beware though that SSIS APIs still often carry DTS prefixes. DTS (Data Transformation Services) is the precursor to SSIS (SQL Server Integration Services) and much of the technology is reused.
First of all, I don't think you are using the right tool for the job. But if still want to use NH for learning purposes, these are my advises:
I highly recommend this lecture: http://msdn.microsoft.com/en-us/magazine/ee819139.aspx
Ayende talks about most of the issues about session handling in non-web scenarios. What we used to do is to follow a pattern-like Model-Per Form. A Model contains a session, but the model lifetime is tied to the life time of the form. This prevents having one session per-application which a very bad decision, in fact Fabio Maulo (NH Lead) says is like having a time-bomb in your application.
Goods new this is not the only approach. Fabio Maulo and a very smart guy named Gustavo Ringel came up with this:
http://fabiomaulo.blogspot.com/2009/01/aspect-conversation-per.html
http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part.html
Good news is not all theory, unNHAddins has a fully functional example of this concepts.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With