James Su
James Su

Reputation: 41

How to access NHibernate.IQueryOver<T,T> within ActiveRecord?

I use DetachedCriteria primarily, it has a static method For to construct an instance. But it seems IQueryOver is more favourable, I want to use it.
The normal way to get an instance of IQueryOver is Isession.Query, and I want get it with ActiveRecord gracefully, anyone knows the way? Thanks.

Upvotes: 0

Views: 1222

Answers (2)

James Su
James Su

Reputation: 41

First, QueryOver.Of<T> return an instance of QueryOver<T, T>, then you build conditions with QueryOver API.

After that, query.DetachedCriteria return the equivalent DetachedCriteria, which can be used with ActiveRecord gracefully.

var query = QueryOver.Of<PaidProduct>()
.Where(paid =>
       paid.Account.OrderNumber == orderNumber
       && paid.ProductDelivery.Product == product)
       .OrderBy(paid=>paid.ProductDelivery.DeliveredDate).Desc;
return ActiveRecordMediator<PaidProduct>.FindAll(query.DetachedCriteria);

Upvotes: 3

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99750

As far as I know, there is no direct support for QueryOver. I encourage you to create an item in the issue tracker, then fork the repository and implement it. I'd start by looking at the implementation of ActiveRecordLinqBase, it should be similar. But instead of a separate class, you could just implement this in ActiveRecordBase. Then wrap it in ActiveRecordMediator to that it can also be used in classes that don't inherit ActiveRecordBase.

Upvotes: 1

Related Questions