RodH257
RodH257

Reputation: 3632

NHibernate 3 Linq query caching

I've just started using LINQ with NHibernate in NHibernate 3, after previously using ICriteria.

Here's an example query:

ISession session = NHibernateSessionManager.Instance.GetSession();

var results = from project in session.Query<Project>()
              where project.ProjectState == ProjectState.Archive
              orderby project.ProjectNumber
              select project;

return results.ToList();

How do I set that to cache? I've had a look around and other questions seem to use a different (perhaps outdated?) syntax, or perhaps I'm doing it wrong...

Upvotes: 5

Views: 1858

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52745

Use the Cacheable() extension method on your Queryable before calling ToList().

Upvotes: 9

Related Questions