0

I am trying to convert some old code to use Fluent Nhibernate.

Old code:

allOrders.OrderBy(x => x.OrdersLineItems.Count);

How do I convert it to something like:

query.AddOrder(new Order(????, true));

Is this even possible?

Thanks in advance

UPDATE: Here is the simplified code I am trying to write:

ICriteria query = FluentSessionManager.GetSession().CreateCriteria<Orders>()
     .AddOrder(new Order(????, true));

The joined table is OrdersLineItems. I need to set the order by the count of the line items. Since I am using paging with a data set that has over 500,000 records, simply pulling all the records into memory and then sorting them will not.

Thanks in advance.

  • already answered here http://stackoverflow.com/a/6845746/671619 and http://stackoverflow.com/a/253999/671619 – Firo Feb 29 '12 at 13:11

1 Answers1

0
ICriteria query = FluentSessionManager.GetSession().CreateCriteria<Orders>()
   .CreateAlias("this.OrderLineItems", "oli")
   .AddOrder(new Order(Projections.Count("oli.Id"), true));

Something like that I should think. It's probably not perfect but at least illustrates that you need to use Projections.Count to get it done.

Fourth
  • 9,163
  • 1
  • 23
  • 28