开发者

How to get the latest object using Castle ActiveRecord

开发者 https://www.devze.com 2023-04-07 06:38 出处:网络
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.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号