0

I am using nHibernate Criteria and I'm stuck on something that seems like it should be really simple. in SQL it would be:

WHERE startPos + length > 17

(startPos and length are two columns on the table). Can anyone help me achieve this with nHibernate

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
Andy
  • 10,412
  • 13
  • 70
  • 95

1 Answers1

0

This is the way how to do that with Criteria in NHibernate:

var criteria = session.CreateCriteria<MyEntity>(); // C# MyEntity

criteria.Add(
  // add restriction
  Restrictions.Gt(
    // left part as a projection
    Projections.SqlProjection(
        "(startPos + length) as myAlias"
        , new[] {"myAlias"}
        , new IType[] {NHibernateUtil.Boolean} )
    // right part 
    , 17
    ));
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Thanks that works great! - I haven't used projections before so I think I'll need a bit of time with the manual now to figure out how it actually works though :) – Andy Dec 15 '13 at 08:29
  • NHibernate is amazing tool. It can do really a lot for us. So do not hesitate and do dive in even more ;) Good luck with NHibernate – Radim Köhler Dec 15 '13 at 08:30