Peter Morlion logo

Blog

How to use NHibernate’s SQLCriterion – take 2

After having an interesting discussion with Stefaan (colleague, friend, ex-colleague and now colleague again) about my previous post on NHibernate’s SQLCriterion, I decided to have another look at my usage of SQLCriterion.

He argued that with SQLCriterion, you’re more or less working around the ORM, which I can agree with. After putting it on StackOverflow, I got three answers and tried all three.

This is what I went with in the end:

ISessionFactory sessionFactory = GetSessionFactory(); 
ISession session = sessionFactory.GetCurrentSession(); 
ICriteria criteria = session.CreateCriteria(); 
return session.QueryOver().Where(c => c.Group.Id == groupId).List();

A more elegant solution.

Leave a Reply

Your email address will not be published. Required fields are marked *