NHibernate Sorting a has many collection -


My organization is dishes and has HasMany collection comments in it.

In an MVC controller action

How do I sort comments in descending order of "enteron"?

How do I sort them out?

  prescription recipe = session. Load & lt; Recipe & gt; (Id); NHibernateUtil.Initialize (recipe.Comments);  

Malcolm

I think I just retweet the comments Will get - this (not particulary sorted), and then fix the archive collection of recipe before displaying the recipe.

Depending on how you have created your class, and your mapping, I think it is the only way since a set and bag mapping, representing the unbored collection in NHibernate.

Something like this:

  recipe recipe = session. Go & lt; Recipe & gt; (Id); Var ordered: = recipe Commands. Order By (Comment => Commented;);  

My follower organization looks something like this:

  public class cookie {// ... ... private ISAT < Comment & gt; _comments = New HashedSet & lt; Comment & gt; (); Public readline collection & lt; Comment & gt; Comments {get {return_comments.ToList (). AsReadOnly (); }} Public Zero Addcomment (Comment c) {if (c! = Null & amp;; _comments.Contains (c)) {c.Recipe = this; _comments.Add (c); }} Public Zero Extraction Comment (Comment c) {if (c! = Null & amp; com.Contains (c)) {c.Recipe = null; _comments.Remove (c); }}}  

and mapping:

  & lt; Class name = "recipe" table = "recipes" & gt; ... & lt; Set name = "comments" access = "field.camelcase-underscore" ... & gt; ... & lt; / Set & gt; & Lt; / Square & gt;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -