In NH 2.x I used a construction like this to circumvent the problem
that you got duplicate entries when eagerly fetching one-to-many
relationships.
public static IQueryable<TEntity>
DistinctDeferred<TEntity>(this IQueryable<TEntity> queryable)
{
var nHibernateQueryable = queryable as
INHibernateQueryable<TEntity>;
if (nHibernateQueryable != null)
{
nHibernateQueryable.QueryOptions.RegisterCustomAction(
c => c.SetResultTransformer(new
DistinctRootEntityResultTransformer()));
}
return queryable;
}
This also works quite nicely with WCF Data Services or WCF RIA
Services when the caller is allowed to append some additional where
clauses. How are we supposed to do this with the new LINQ provider in
NH 3.x?