tags:

views:

92

answers:

1

I need to create a query in NHibernate that would search for a product of two columns, like this:

WHERE a*b = param1

leaving efficiency aside (assume I have little rows or actual query will have extra conditions that will exploit some indexes) how do I do it in NHibernate? Preferably the solution should work with DetachedCriteria. I know I could use native SQL with Expression.Sql() but is there any other, better, way? Can I do this in HQL?

+1  A: 

You can do this with HQL or Expression.Sql as you mentioned. HQL supports many different SQL expressions; see this section.

For example:

session.CreateQuery("from test t where t.a * t.b = 4").List();
Stuart Childs