I am using NHibernate for my database management.
In one class I am calculating a property using this formula:
(SELECT MIN(x.timestamp) FROM (SELECT MAX(r.Timestamp) AS timestamp, r.Meter_Id FROM Reading r, Meter m WHERE r.Meter_Id = m.Id AND m.Store_Id = Id GROUP BY r.Meter_Id) AS x)
The generated query looks like this:
(SELECT MIN(x.timestamp) FROM (SELECT MAX(r.Timestamp) AS timestamp, r.Meter_Id FROM Reading r, Meter m WHERE r.Meter_Id = m.Id AND m.Store_Id = this_.Id GROUP BY r.Meter_Id) AS this_.x)
Obviously the name in the AS statement is renamed to this_.x, which causes the error.
It seems to be a known bug: NHibernate JIRA #NH-2878
Does enyone have a solution for this?
I could be mistaken, but I don’t actually see why you need the alias in that particular formula.
In a more general sense, you have a few options: