Filter and maybe some other basic operations. NHiberante additionally supports OrderBy or Last and First for example. This is useful if an entity has a huge collection associated, but only ever wants specific items from the collection.
For example consider a User entity with associated Orders. Over time a user may accumulate a large amount of Orders, i.e. loading them into memory completely would be expensive. We are only ever interested in small subsets of the Orders, e.g. the newest three Orders. With NHibernate this could be done in business code by filtering the Orders collection in the User object, e.g.
Code:
this.Orders.Take(3)
to retrieve the desired subset and NHibernate would translate the LINQ calls to SQL as needed. This way the code is easily testable as it is more persistance ignorant and the domain objects need less orchestration code to perform the queries, e.g.
Code:
repository.retrieveNewestOrders()
.
Maybe I am just stuck to this way of thinking though. Suggestions for alternatives or improvements are also welcome :).