I use these a lot.
public static class NHLinqHelper { public static INHibernateQueryable<TValue> DistinctRoot<TValue>(this INHibernateQueryable<TValue> query) { query.QueryOptions.RegisterCustomAction(c => c.SetResultTransformer(new DistinctRootEntityResultTransformer())); return query; } public static INHibernateQueryable<TValue> Cached<TValue>(this INHibernateQueryable<TValue> query) { query.QueryOptions.SetCachable(true); return query; } }
This just makes the most common query options available fluently. It isn’t perfect, in that using standard LINQ operators changes the declared type, which means you need to set these at the start, not the end of the query. But if you use NHLinq, you’re used to that.
Technorati Tags: Nhibernate.Linq