O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

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

Using session.Refresh

Especially in desktop applications, it may be necessary to reload an entity to reflect recent changes made in a different session. In this recipe, we'll use session.Refresh to refresh an entity's data as it is being manipulated by two sessions.

Getting ready

Following Configuring NHibernate with App.config from Chapter 2, setup a console application for NHibernate with our Eg.Core model from Chapter 1.

How to do it...

  1. Add the following code to your Main method.
    var sessionA = sessionFactory.OpenSession(); var sessionB = sessionFactory.OpenSession(); Guid productId; Product productA; Product productB; productA = new Product() { Name = "Lawn Chair", Description = "Lime Green, Comfortable", UnitPrice = 10.00M }; using (var tx = sessionA.BeginTransaction()) ...

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