I have this nhibernate query:
var q =
NHibernateSession.Current.CreateSQLQuery
(
@"SELECT LastestEvents.*
FROM (
SELECT DISTINCT SbQcontainer.Container
FROM HistoricEvents
SbQcontainer WHERE SbQcontainer.LineCompany_Id = :lineCompany) as Sbq
JOIN HistoricEvents as LastestEvents
ON LastestEvents.id = (
SELECT TOP(1) id
FROM HistoricEvents mi
WHERE mi.Container = Sbq.Container and mi.LineCompany_Id = :lineCompany
ORDER BY mi.Date DESC
)"
).SetResultTransformer(Transformers.AliasToBean(typeof(HistoricEvent)));
q.SetParameter("lineCompany",lineCompany.Id);
q.SetCacheable(false);
var results = q.List<HistoricEvent>().ToList();
It looks for the lastest events on each container for the given lineCompany, it works, but i dont know how to set this resultset to a list of T HistoricEvent, i try this line:
.SetResultTransformer(Transformers.AliasToBean(typeof(HistoricEvent)));
But throws NHibernate.PropertyNotFoundException:Could not find a setter for property 'Event_Id' in class 'HistoricEvent'.
Is there any way to do this?, or maybe doing this same query using the ICriteria API?
Thx in advance.