I've got a Table of OrderDetails objects and I'd like to get OrderNumber of the latest Order in the database i.e. the Order with the highest OrderDetailsID. In SQL I can do the following:
select Top 1 OrderNumber from orderdetails order by OrderDetailsID desc开发者_Python百科
How would I go about getting the same thing using ActiveRecord, what Criteria should I be specifying in FindOne(...) call?
ActiveRecord.AsQueryable<OrderDetails>()
.OrderByDescending(o => o.OrderDetailsID).First().OrderNumber
I can't make it any shorter :) you could also do:
FindFirst(typeof (OrderDetails),
new[] {NHibernate.Criterion.Order.Desc("OrderDetailsID")}, null).OrderNumber;
精彩评论