This is really basic and I have read the million warnings along the lines of "read the docs", "learn the basics", "search the forums" etc and I've still come up short after several hours now of trying to do what is seemingly a simple task. The problem is, as someone new to NHibernate, I'm still not sure of what terminology to search for hence it being hard to find what i'm after. So, in summary, apologies for the stupid post...
I'm using NHibernate for usual CRUD actions without problem and very much enjoying it. However, for one page on my asp.net site I simply want to show a very basic gridview with some summary, read-only data on it (a list of dates and count of requests per date). I'm using CreateSqlQuery to get the data I need (which through the debugger I can see is working) but I've no idea how to bind that IList to my gridview because I can't seem to map the objects returned in the IList to anything. Normally I would just use the standard dataReader but I'd prefer to stick with NHibernate.
This is what I'm returning:
Code:
public System.Collections.IList GetSummary()
{
IList requestsList;
using(ISession session = factory.OpenSession())
{
requestsList = session.CreateSQLQuery("SELECT CONVERT(char(10), request_date, 120) as req_date, sum(request_id) as req_count FROM tbl_request GROUP BY CONVERT(char(10), request_date, 120)")
.AddScalar("req_date", NHibernateUtil.Date)
.AddScalar("req_count", NHibernateUtil.Int64).List();
}
return requestsList;
}
If I try to just bind that IList to my gridview I see all the object array properties (IsReadOnly, IsFixedLength etc) in each row which is obviously not what i'm after.
If I try to iterate the object arrays in the IList and convert to anything I get "Cannot apply indexing with [] to an expression of type 'object'" restricting me reaching the values i'm after (admitidly this is more a limitation of my .net skills - but I dont feel this is the 'Nhibernate' way regardless).
As I see it, the problem is I don't have a class for each row of the data returned, which I could easily do but then I have no idea how I would map that class because there is nothing in the database to map it to that reflects what it represents (I.e. a date and a count of requests that occured on that date). Which is why i used a custom query in the first place.
Any help, even a link to the right place in the docs would be very much appreciated.