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.