Is there any way to use expressions in the Select clause?
E.g.:
select u.Age/2 from User u
I'm having this exception right now:
NHibernate.QueryException: ',' expected in SELECT before:/ [select u.Age/2 from Business.Entities.User u]
Is there any way to use expressions in the Select clause?
E.g.:
select u.Age/2 from User u
I'm having this exception right now:
NHibernate.QueryException: ',' expected in SELECT before:/ [select u.Age/2 from Business.Entities.User u]
Yes, you can do that. The result of the query will be a List of Object[], where each element of the array is the result of the column calculation. In your example, if the table had 10 rows, then you'd get back a list of 10 items, each with a single-item Object[] containing the age/2 value.
I'd link to the part of the Hibernate docs that describe this behaviour (it has a special name, I can't remember what it is), but hibernate.org seems to be down again.
You just want get the result of u.Age divided by two? You can use HQL but I find it's easier to change the formula attribute in the mapping file.
ie:
<property name="HalfAge" formula="Age / 2" />