How to apply DistinctRootEntityResultTransformer to all queries in NHibernate
When executing queries with eager loading some one-to-many associations i'm always using DistinctRootEntityResultTransformer (to not to have duplicated Video entries in a result list) like:
var video = session.QueryOver&l开发者_如何学编程t;Video>().Where(x => x.Id == 146)
.Fetch(x => x.Genres).Eager
.TransformUsing(new DistinctRootEntityResultTransformer())
.List();
Is there a way to apply this globally to all the queries, at the ISessionFactory configuration time? Cause in most cases I certainly want it to be enabled.
No, it's not possible.
You could do that in a base repository class.
精彩评论