Archive for category ActiveRecord

ActiveRecord moving to NHibernate 2

Aparently the ActiveRecord guys want to move ActiveRecord to NHibernate 2.0, for now, this means, move to NHibernate trunk (just for now).

This will bring more capabilities to ActiveRecord, for example, here I show you how to use DetachedQuery with ActiveRecord. Moving to NHibernate 2.0, I will able to commit a patch with this support without need uNHAddIns.ActiveRecord.dll.

At this thread you can see the guys of developer list of Castle voting for do this play.

Another key feature to take advantages is Event Listeners. At chat with Fabio Maulo:

  • Me: “I can’t see the advantages using Event Listeners with ActiveRecord at Validation, AR validate before Save and do this work
  • Fabio: “How you can intercept the validation process untill make the Save?
  • Me: “You can’t
  • Fabio: “You just answered yourself

1 Comment

ActiveRecord and support for DetachedQuery

This weekend I wrote the classes necessaries to support IDetachedQuery with ActiveRecord. DetachedQuery it’s not available yet at any version of NHibernate, you can find it only in uNHAddIns and at the SVN of NHibernate.

I add a project to uNHAddIns: uNHAddIns.ActiveRecord. This consist in the classical classes for ActiveRecord with support for IDetachedQuery.

If we want support for IDetachedQuery using ActiveRecord you must this clases:

  • ActiveRecordBase
  • ActiveRecordBase<T>
  • ActiveRecordValidationBase
  • and ActiveRecordValidationBase<T>

Now you will able to do somethings like this:

Customer[] customers = Customer.FindAll(new DetachedQuery("from Customer Order By Name"));

The new methods for ActiveRecordBase and ActiveRecordValidationBase are:

  • public static bool Exists(Type targetType, IDetachedQuery detachedQuery);
  • public static Array FindAll(Type targetType, IDetachedQuery detachedQuery);
  • public static object FindFirst(Type targetType, IDetachedQuery detachedQuery);
  • public static object FindOne(Type targetType, IDetachedQuery detachedQuery);
  • public static Array SlicedFindAll(Type targetType, int firstResult, int maxResults, IDetachedQuery detachedQuery);

And the new methods for ActiveRecordBase<T> and ActiveRecordValidationBase<T> are:

  • public static bool Exists(IDetachedQuery detachedQuery);
  • public static T[] FindAll(IDetachedQuery detachedQuery);
  • public static T FindFirst(IDetachedQuery detachedQuery);
  • public static T FindOne(IDetachedQuery detachedQuery);
  • public static T[] SlicedFindAll(int firstResult, int maxResults, IDetachedQuery detachedQuery);

This implementation no hide any feature of ActiveRecord base classes, it’s a extension for IDetachedQuery support.

Requeriments

This classes are provided in the assembly uNHAddIns.ActiveRecord.dll. And this assembly require the main assembly of the project: uNHAddIns.dll.

Downloads here

Wiki entry

2 Comments