views:

101

answers:

1

Hi,

I'm trying to query using Castle and return a strong-typed array or IList for later use in data binding, so from i read a ProjectionQuery would be my best choice, but how would i transform this to a projection query:

        HqlBasedQuery hql = new HqlBasedQuery(typeof(TrackingRule), 
                                          QueryLanguage.Hql,
                                          "SELECT AC.TrackingRule FROM Account_Rule as AC WHERE AC.Account.ID = " + 63);

Thanks In Advance

Yehia A.Salam

A: 

It looks like you are just trying to return a list of objects. Projection queries are usually used to return only some columns, which doesn't appear to be what you need here.

You can get a strongly typed ArrayList with what you have:

HqlBasedQuery hql =
  new HqlBasedQuery(typeof(TrackingRule), QueryLanguage.Hql,
        "SELECT AR.TrackingRule FROM Account_Rule as AR WHERE AR.Account.ID = "
           + 63);
ArrayList resultsList = (ArrayList) ActiveRecordMediator.ExecuteQuery(hql);

Here's an alternative that returns an array:

SimpleQuery<TrackingRule> sq =
  new SimpleQuery<TrackingRule>(
        "SELECT AR.TrackingRule FROM Account_Rule as AR WHERE AR.Account.ID = "
           + 63);
TrackingRule [] arrayOfTrackingRules =
  (TrackingRule []) ActiveRecordMediator.ExecuteQuery(sq);
Michael Maddox