NHibernate Forge
The official new home for the NHibernate for .NET community

Enumerating First Level Cache Entities

Wiki Page Hierarchy

Pages

Page Details

First published by:
Ricardo Peres
on 03-01-2011
Last revision by:
Ricardo Peres
on 03-04-2011
This page has not yet been rated
Article
Comments (0)
History (2)

Enumerating First Level Cache Entities

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>();

Recent Comments

Leave the first comment for this page.
View All
Powered by Community Server (Commercial Edition), by Telligent Systems