SqlRestriction where is it?

186 views
Skip to first unread message

MattO

unread,
Oct 5, 2011, 10:13:18 AM10/5/11
to nhusers
In NHibernate we are suppose to use the Restrictions class because the
Expressions class is "semi-depricated". However the Restrictions
class does not have a .Sql or .sqlRestriction (java has this).

What am I missing? How do you do a Sql string restriction with the
Restrictions class?

Jason Meckley

unread,
Oct 5, 2011, 4:00:42 PM10/5/11
to nhu...@googlegroups.com
you could try SqlRestrictions.Whatever, but really why would you mix an object query with a sql query. if you need sql drop to session.createsqlquery("select * from table where...")

MattO

unread,
Oct 7, 2011, 4:23:43 PM10/7/11
to nhusers
I actually figured it out and I didn't have to use a expression for
dynamic where clause. I'm dealing with legacy database and there are
some problems with it that do not map well to criteria class...

I couldn't find the SqlRestrictions class, where is it located? The
only thing I've found so far is Expression.Sql() and SqlProjection().

Jason Meckley

unread,
Oct 11, 2011, 9:03:21 AM10/11/11
to nhu...@googlegroups.com
probably doesn't exist then. I was referring to it as something to try. Glad to hear you got it working!

Marios Skounakis

unread,
Oct 12, 2011, 3:39:02 AM10/12/11
to nhu...@googlegroups.com
Restrictions can be defined not only on a property but also on a projection. And you can use SqlProjection inside a restriction.

So, instead of
q.Add(Expression.Sql("abs(some_numeric_field) > 0"))
you can do
q.Add(Restrictions.Gt(Projections.Sql("abs(some_numeric_field)", <insert rest of parameters for Sql Projection as needed>), 0))



--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


Reply all
Reply to author
Forward
0 new messages