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

Follow the Getting ready step in the Save entities to the database recipe in this chapter.

How to do it…

  1. Add a new folder named SessionRefresh to the SessionRecipes project.
  2. Add a class named Recipe to the folder:
    using System; using NH4CookbookHelpers; using NH4CookbookHelpers.Queries.Model; using NHibernate; namespace SessionRecipes.SessionRefresh { public class Recipe : QueryRecipe { protected override void Run(ISessionFactory sessionFactory) { using (var sessionA = sessionFactory.OpenSession()) ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.