You have accessed an ActiveRecord class t.hat wasn't properly initialized. The only explanation is that the call to ActiveRecordStarter.Initialize() didn't include System.Int32 class

Actually, that isnt the only explanation. It is a Red Herring. It will distract you from the actual problem, and that is your are using Castle.ActiveRecord.Queries.SimpleQuery<int> INSTEAD of Castle.ActiveRecord.Queries.ScalarQuery<int>, since you are probably just trying to pull just an integer like what im doing:


string hql = "SELECT max(map.HighestNewRating) FROM XXX map WHERE map.Id = ?";

Im guessing that you can only use SimpleQuery to return values that have been initialised, and you cant return anything else, whereas the ScalarQuery can be used for Ints and strings and stuffs like that - in my opinion that is just overcomplicating things, why not just have one query structure, instead of two? Both implement from Castle.ActiveRecord.Queries.HqlBasedQuery but then just add their own flavour of blah'ness ontop to make things extra complicated.



string hql = "SELECT max(map.HighestNewRating) FROM ModelClassTypeMap map WHERE map.Id = ?";

SimpleQuery<int> query = new SimpleQuery<int>(hql, id);

int[] response = query.Execute();



Will give you an error, whereas this wont:



                string hql = "SELECT max(map.HighestNewRating) FROM ModelClassTypeMap map WHERE map.Id = ?";

                
ScalarQuery<int> query = new ScalarQuery<int>(typeof(ModelClassTypeMap), hql, id);
                
                
int response = query.Execute();

                
return response;


Also, why do you have to declare the type when doing a ScalarQuery ? Whats that all about?

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

Please add 4 and 8 and type the answer here: