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…
Add a new folder named
SessionRefreshto theSessionRecipesproject.Add a class named
Recipeto 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...