I'm trying to use the following code to return an unmanaged entity (well, I think that's the term - it's not a mapped entity, but I thought I had to import the classtype)
Code:
string sql = "SELECT eb.EventID as CourseEventId, " +
"ce.fromdate as FromDate, " +
"l.name as LocationName, " +
"isnull(v.name, '') as VenueName, " +
"ce.maxdelegates as MaxDelegates, " +
"SUM(CASE eb.Status WHEN 'Firm' THEN 1 ELSE 0 END) AS Firm as Firm, " +
"SUM(CASE eb.Status WHEN 'On Waiting List' THEN 1 ELSE 0 END) AS OnWaitingList as OnWaitingList," +
"SUM(CASE WHEN eb.Status = 'Invoiced' AND eb.CancelDate IS NULL THEN 1 ELSE 0 END) AS Invoiced as Invoiced," +
"SUM(CASE eb.Status WHEN 'Cancelled' THEN 1 ELSE 0 END) AS Cancelled as Cancelled," +
"SUM(CASE eb.Status WHEN 'Transferred' THEN 1 ELSE 0 END) AS Transferred as Transferred," +
"ce.status as Status" +
"FROM " +
"EventBooking eb INNER JOIN " +
"Events ce ON eb.EventID = ce.EventID INNER JOIN " +
"Courses c ON ce.CourseID = c.CourseID INNER JOIN " +
"Locations l ON ce.LocationID = l.LocationID LEFT OUTER JOIN " +
"tblVenues v ON ce.VenueID = v.VenueID " +
"WHERE " +
//"c.CourseID = :courseId " +
"c.CourseID = 2545 " +
"GROUP BY " +
"eb.EventID, ce.fromdate, l.name, v.name, ce.maxdelegates, ce.status";
List<CourseEventBookingInfo> results = (List<CourseEventBookingInfo>)session
.CreateSQLQuery(sql)
.AddEntity("courseEventBookingInfo", typeof(CourseEventBookingInfo))
.List<CourseEventBookingInfo>();
note I have also tried adding:
Code:
.SetResultTransformer(Transformers.AliasToBean(typeof(CourseEventBookingInfo)))
to the creation of the query.
I'm importing the class using the following (in a hbm.xml file)
Code:
<import class="ReportingEntities.CourseEventBookingInfo, ReportingEntities"/>
I continually receive the following error:
Code:
NHibernate.MappingException: No persister for: ReportingEntities.CourseEventBookingInfo, ReportingEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Am I not using CreateSQLQuery properly? I've searched around everywhere, and have seen Sergey write a couple of times that the documentation around CreateSQLQuery needs to be updated due to some changes in the implementation, but the documentation in the latest release (1.2 CR1) doesn't appear to have many differences.
What am I doing wrong?
OR
Is there a better way to do this?
TIA.