Head.SmackOnTable();

Contains Nuts.

Archive for October, 2007

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

without comments

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?

Written by Monty

October 18th, 2007 at 3:55 am

Posted in .NET, Moments

How to skin a live monkey by using just your teeth

without comments

… has nothing todo with what im about to tell you. No, really, it dosent. Although, its about the same – a quick how to on how to write SQL JOIN’s with nHibernates "super-shitty" HQL

Say heres your bog standard JOIN statement that you want to run:

SELECT * from MODEL INNER JOIN ModelClassTypeMap ON Model.Id = ModelClassTypeMap.ModelID  WHERE ClassTypeId=2 ORDER BY HighestNewRating DESC

You cant simply just rewrite that in HQL. HQL dosent use the "ON" directive. So you have to do multiple FROM statements, then tell it what you want to select. Sound easy? Welp, it isnt:

SELECT model FROM Model model, ModelClassTypeMap classTypeMap WHERE model.Id = classTypeMap.Model AND classTypeMap.ClassType = ? ORDER BY  classTypeMap.HighestNewRating DESC

To me this just seems retarded. You cant copy the sql that youv spent minutes perfecting, but you have to go and rewrite the whole thing so a 3 year old blind child whos been on cocaine for the last 6 months can understand it. Why not just do it so that you can reuse queries that you already have, instead of having to rewrite the whole way you write them? HQL is a poor mans SQL, its shoddy and flaky, and hardly documented.

Happiness is a warm gun.

Written by Monty

October 10th, 2007 at 10:55 am

Posted in .NET

Small Tip – Preprocessor Directives

without comments

Some people say that using preprocessor directives is just plain evil in c#.net, but it has uses. For example, the #warning and the #error directives will generate a warning and / or an error when used, like so:

C:\Work\SVN\xxx\xxx\xxx\xxx.cs(67,10): warning CS1030: #warning: ‘REMOVE ME BEFORE GO LIVE’

Quite useful as a reminder…and you can replace that with an error if you want to make sure something dosent compile, until you have finished the code (useful for working over weekends, in my opinion at least)

Written by Monty

October 10th, 2007 at 4:03 am

Posted in .NET

Announcing Sky Motoring

without comments

If you have visited the Sky.com site from Monday, you might have noticed the following:

image

Sky Motoring has gone live!

image

Written by Monty

October 2nd, 2007 at 2:33 am

Posted in .NET, Misc