NHibernate in C # application how to manage a session

I'm new to the NHibernate world, and I'm starting to create a simple C # application for Windows Form that imports some XLS files into a database (SQL2008), develops data, and exports a CSV file. I tried to find some usage examples and NHibernate session management; some of them are useful for web applications. I saw that in the MVC application, the NHibernate session is created in the Start application, but I cannot figure out when I should create the NHibernate session in the Windows Form application.

Can anybody help me? Thanks!

+4
source share
3 answers

Regarding feedback, I suggest you study using SSIS for this kind of work. In addition to being designed for ETL processes such as SSIS, they can also be re-executed as needed, and there is no need to create code. Although, if you want, it is not difficult to write .NET code to run SSIS packages as needed. Here is an example . Beware though DTS prefixes are still in the SSIS API. DTS (Data Transformation Services) is the forerunner of SSIS (SQL Server Integration Services), and most of the technology is reused.

+2
source

First of all, I don’t think you are using the right tool for the job. But if you still want to use NH for training purposes, these are my recommendations:

I highly recommend this lecture: http://msdn.microsoft.com/en-us/magazine/ee819139.aspx

Ayende talks about most of the problems associated with session handling in scripts other than websites. What we did was follow a form-for-type template. The model contains a session, but the lifetime of the model is tied to the lifetime of the form. This prevents the use of one session for one application, which is a very bad decision, because Fabio Molo (NH Lead) says that you have a time bomb in your application.

The product is new, this is not the only approach. Fabio Molo 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

The good news is not all theory; unNHAddins has a fully functional example of these concepts.

NTN

+2
source

For starters, I would not recommend NHibernate for this scenario - import / export and multiple data stores are actually not.

However ... Web applications typically create a request for an NHibernate session to a page (for example, in a session start event or as an action filter). A factory session is usually created when the application starts.

For a Windows forms application, you can take a look at the work item template. Your session will probably want to follow this.

0
source

Source: https://habr.com/ru/post/1346324/


All Articles