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.
Follow the Getting ready step in the Save entities to the database recipe in this chapter.
Add a new folder named
SessionRefresh
to theSessionRecipes
project.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()) using (var sessionB = sessionFactory.OpenSession()) { int productId; var productA = new Product() { Name = "Lawn Chair", Description = "Lime Green...