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...
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 .
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.