Custom HQL AST visitor

48 views
Skip to first unread message

pvginkel

unread,
May 17, 2013, 8:48:31 AM5/17/13
to nhu...@googlegroups.com
We're in the process of converting a legacy application to NHibernate. One of the "interesting" aspects of this application is that part of it is written in Magic, which does not allow columns to have NULL, but instead requires it to have a space. This means that some tables do not allow NULL in string columns, and some tables do.

I have already implemented some functionality to hide this fact using a few IType implementations. These work nicely and loading and saving entities already automatically convert spaces to NULL's.

However, I can't seem to find a way to fix querying. We're primarily using LINQ as our query mechanism, and I would like the following:

db.Addresses.Where(p => p.Street == null)

to be converted to:

where o.Street = ' '

instead of:

where o.Street is null

I've already implemented some custom LINQ functions, but because the developer does not know what fields to apply these functions to, I would very much prefer an automated mechanism. I have the feeling the best way to accomplish this may be using a custom HQL AST visitor (maybe there are better solutions), but I can't seem to find an extension point to provide something like that.

What is the best way to get this to work?

Ricardo Peres

unread,
May 23, 2013, 5:09:26 AM5/23/13
to nhu...@googlegroups.com
You can do it with a custom interceptor (a class derived from ExpressionVisitor), like this: http://weblogs.asp.net/ricardoperes/archive/2013/05/23/intercepting-linq-queries.aspx.
Look for a BinaryExpression where some property (left value) is being compared to null (right value) and replace the right value for "".

RP

Pieter van Ginkel

unread,
May 23, 2013, 11:58:14 AM5/23/13
to nhu...@googlegroups.com

Thank you for the suggestion. However, i need something at a lower level, the hql ast level.

--
You received this message because you are subscribed to a topic in the Google Groups "nhusers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhusers/58GRDMwwzPA/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gunnar Liljas

unread,
May 23, 2013, 4:28:44 PM5/23/13
to nhu...@googlegroups.com
The db.Addresses.Where(p => p.Street == null) case would be easy to solve with the approach suggested by Ricardo, and INSERTs and UPDATEs can quite likely be handled by a plain ol' IInterceptor. Can you describe where you need to go deeper?

/G


2013/5/23 Pieter van Ginkel <pvgi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages