How to enable NHibernate Second-Level Cache with NHibernate Linq Provider 1.0 ?
Second-Level Cache seems to work only with ICriteria usage.
Yes, I finally worked this one out:
public IQuerable<T> CreateLinqQuery()
{
var query = session.Linq<T>();
query.QueryOptions.SetCachable(true);
return query;
}
Update As others have pointed out, in NH3, use query.Cacheable(). However be very careful to do it like this:
// Correct way:
query = query.Cacheable();
// This won't work:
query.Cacheable();
For NHibernate 3+ it's session.Query<T>().Cacheable()
NH3 RC version:
public IQueryable<T> Queryable<T>()
{
IQueryable<T> queryable = SessionFactory.OpenSession().Queryable<T>();
queryable = queryable.Cacheable<T>();
return queryable;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With