How to enumerate local (first level cache) session entities:
public static class SessionExtensions
{
public static IEnumerable<T> Local<T>(this ISession session)
{
ISessionImplementor impl = session.GetSessionImplementation();
IPersistenceContext pc = impl.PersistenceContext;
foreach (Object key in pc.EntityEntries.Keys)
{
if (key is T)
{
yield return ((T) key);
}
}
}
}
//sample usage:
IEnumerable<Post> localPosts = session.Local<Post>();