Reputation: 616
I can select int and string literals in HQL like so:
select 'a string' as StringLiteral, 1 as IntLiteral from Eg.MyClass
but I haven't found a way to select a boolean literal. I've tried select true ...
, and select new bool true ...
but those cause HQL syntax exceptions.
Is there a way to select a boolean literal in HQL?
I have found a workaround (select case when (1=1) then true...
), but that seems inefficient...
Upvotes: 2
Views: 3432
Reputation: 9854
select cast(1 as bool) as bitLiteral from Eg.MyClass
NHibernate usually supports the same features as Hibernate. This was elaborated from this answer. I have tested it with NHibernate.
NHibernate maps SQL bit
type to .Net bool
type.
The cast is required in plain SQL too, as SQL (at least SQL Server Transact-SQL) lacks bit literals.
Upvotes: 2
Reputation: 64628
There are actually no real booleans in SQL (as in Select 1=1
), except of in conditions. HQL turns "true" and "false" into 0 and 1 I think (something you can configure somewhere), but I guess it is still an integer.
Simplest things you can most probably do is convert the integer to a boolean in memory after the query.
Upvotes: 1