Custom query with Castle ActiveRecord

后端 未结 2 662
甜味超标
甜味超标 2020-12-30 17:19

I\'m trying to figure out how to execute a custom query with Castle ActiveRecord.

I was able to run simple query that returns my entity, but what I really need is t

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 18:06

    Be aware though, if you're using ActiveRecord 1.0.3 (RC3) as I was, this will result in a runtime InvalidCastException. ActiveRecordMediator.ExecuteQuery returns an ArrayList and not a generic ICollection. So in order to make it work, just change this line:

    var results = (ICollection) ActiveRecordMediator.ExecuteQuery(query);
    

    to

    var results = (ArrayList) ActiveRecordMediator.ExecuteQuery(query);
    

    and it should work.

    Also note that using count(1) in your hql statement will make the query return an ArrayList of String instead of an ArrayList of object[] (which is what you get when using count(*).)

    Just thought I'd point this out for the sake of having it all documented in one place.

提交回复
热议问题