O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Opening a session to the database

We will implement the code such that our product inventory application can open a session to the database.

  1. Add another row to the grid of MainWindow. In this new third row, place an additional button called btnCreateSession with content Create Session. Furthermore, define an event handler for the click event. The code for the button should look similar to the following code snippet:
    <Button x:Name="btnCreateSession" 
      Content="Create Session" 
      Click="btnCreateSession_Click" 
      Grid.Row="2"/>
  2. In the event handler of this button, add the following code:
    private void btnCreateSession_Click(object sender,RoutedEventArgs e) { var factory = CreateSessionFactory(); using (var session = factory.OpenSession()) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required