Я думаю, что я просто извлеку комментарии «как есть» (не отсортированные по частям), а затем просто отсортировал коллекцию комментариев в рецепте, прежде чем отобразить комментарии.
В зависимости от того, как вы создали свой класс и свое отображение, я думаю, что это единственный способ, поскольку отображение набора и сумки представляет неупорядоченные коллекции в NHibernate.
Примерно так:
Recipe recipe = session.Get<Recipe> (id);
var orderedComments = recipe.Comments.OrderBy ( comment => comment.EnteredOn );
foreach( Comment c in orderedComments )
{
// display the comment
}
Где моя сущность Reciple выглядит примерно так:
public class Recipe
{
// ...
...
private ISet<Comment> _comments = new HashedSet<Comment>();
public ReadOnlyCollection<Comment> Comments
{
get { return _comments.ToList().AsReadOnly(); }
}
public void AddComment( Comment c )
{
if( c != null && !_comments.Contains (c) )
{
c.Recipe = this;
_comments.Add (c);
}
}
public void RemoveComment(Comment c )
{
if( c != null && _comments.Contains (c) )
{
c.Recipe = null;
_comments.Remove(c);
}
}
}
и отображение:
<class name="Recipe" table="Recipes">
...
<set name="Comments" access="field.camelcase-underscore" ... >
...
</set>
</class>