Hey all,
I'm trying to create a native sql query to get a summary of all hits for a company in a specified month. The table has the columns (ID, Company, Date).
I'm trying the following:
Code:
IList list = _session.CreateSQLQuery(
String.Format(
"SELECT Company, count(*) " +
"FROM History" +
"WHERE (DATENAME(m, [Date]) = '{0}') AND (DATENAME(yy, [Date]) = '{1}') " +
"GROUP BY Company "
, month, year))
.AddScalar("Company", NHibernateUtil.String)
.AddScalar("Hits", NHibernateUtil.Int32)
.List();
I'm getting the exception "IndexOutOfRangeException: Hits". That means that somehow the scalar for hits cannot be resolved. The query works fine when I leave the second AddScalar("Hits", ..) out.
Does anyone know how I can get hold of the count(*)? Any help is greatly appreciated!