Can I set NHibernate's default "OrderBy" to be "CreatedDate" not "Id"?
- by Chris F
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.