I need to return a constant from an HQL query in NHIbernate
SELECT new NDI.SomeQueryItem(user, account, ' + someNumber + ') FROM NDI.SomeObject object
I am trying for something like above. I’ve tried this:
SELECT new NDI.SomeQueryItem(user, account, :someNumber) FROM NDI.SomeObject object
And then later:
.SetParameter('someNumber', 1).List<SomeQueryItem>();
But in the first case I get a ‘Undefined alias or unknown mapping 1’. Which makes some sense since it probably thinks the 1 is an alias.
For the second I get a ‘Undefined alias or unknown mapping :someNumber’ which again makes some sense if it never set the parameter.
I have to believe there’s some way to do this.
Please feel free to continue to believe there is some way to do this – but with HQL there isn’t!
Why would you want to anyway? If you want to update the value this property to the value you specify, then do so after you’ve loaded the objects. Alternatively, if your result set doesn’t quite match to your objects, you could alway use a SQL query (which you can still do via an NHibernate session). But the purpose of NHibernate is to map what’s in your database onto objects, so specifying a manual override like this is quite rightly not allowed.