我希望在当前会话中加载所有持久对象。
我知道与会话关联的持久上下文缓存,包含当前会话中加载的所有对象的字典。谁能告诉我如何知道加载到 IPersistenceContext 缓存中的所有对象?
// 创建我们的 NHibernate 会话工厂
var sessionFactory = CreateSessionFactory();
using (var session = sessionFactory.OpenSession())
{
Employee emp;
// populate the database
using (var transaction = session.BeginTransaction())
{
emp = session.Query<Employee>().Where(x => x.Name == "Bargin Basin").FirstOrDefault();
var entries = session.GetSessionImplementation().PersistenceContext.EntityEntries;
foreach (var item in entries)
{
var entityEntry = entries[item];
//I want the objects of my type like..
//Employee persistedEmp = entityEntry as Employee;
}
}
}