Can I set NHibernate's default "OrderBy" to be "CreatedDate" not "Id"?

Posted by Chris F on Stack Overflow See other posts from Stack Overflow or by Chris F
Published on 2010-04-27T15:30:38Z Indexed on 2010/04/27 16:03 UTC
Read the original article Hit count: 163

Filed under:
|

This is an oddball question I figure.

Can I get NHibernate to ask SQL to sort data by CreatedDate by default unless I set an OrderBy in my HQL or Criteria? I'm interested in knowing whether this sort can be accomplished at the DB level to avoid bringing in LINQ.

The reason is that I use GUIDs for Ids and when I do something like this:

Sheet sheet = sheetRepository.Get(_someGUID);
IList<SheetLineItems> lineItems = sheet.LineItems;

to fetch all of the lineItems, they come back in whatever arbitrary way that SQL sorts that fetch, which I figure is GUID. At some point I'll add ordinals to my line items, but for now, I just want to use CreatedDate as the sort criteria. I don't want to be forced to do:

IList<SheetLineItem> lineItems = sheetLineItemRepository.GetAll(_sheetGUID);

and then writing that method to sort by CreatedDate. I figure if everything is just sorted on CreatedDate by default, that would be fine, unless specifically requested otherwise.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about sql