Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Recipe recipe = session.Load<Recipe>(id);
  2. NHibernateUtil.Initialize(recipe.Comments);
  3.  
  4. Recipe recipe = session.Get<Recipe> (id);
  5.  
  6. var orderedComments = recipe.Comments.OrderBy ( comment => comment.EnteredOn );
  7.  
  8. foreach( Comment c in orderedComments )
  9. {
  10. // display the comment
  11. }
  12.  
  13. public class Recipe
  14. {
  15. // ...
  16. ...
  17.  
  18. private ISet<Comment> _comments = new HashedSet<Comment>();
  19.  
  20. public ReadOnlyCollection<Comment> Comments
  21. {
  22. get { return _comments.ToList().AsReadOnly(); }
  23. }
  24.  
  25. public void AddComment( Comment c )
  26. {
  27. if( c != null && !_comments.Contains (c) )
  28. {
  29. c.Recipe = this;
  30. _comments.Add (c);
  31. }
  32. }
  33.  
  34. public void RemoveComment(Comment c )
  35. {
  36. if( c != null && _comments.Contains (c) )
  37. {
  38. c.Recipe = null;
  39. _comments.Remove(c);
  40. }
  41. }
  42. }
  43.  
  44. <class name="Recipe" table="Recipes">
  45. ...
  46. <set name="Comments" access="field.camelcase-underscore" ... >
  47. ...
  48. </set>
  49. </class>
Add Comment
Please, Sign In to add comment