Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Recipe recipe = session.Load<Recipe>(id);
- NHibernateUtil.Initialize(recipe.Comments);
- Recipe recipe = session.Get<Recipe> (id);
- var orderedComments = recipe.Comments.OrderBy ( comment => comment.EnteredOn );
- foreach( Comment c in orderedComments )
- {
- // display the comment
- }
- 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>
Add Comment
Please, Sign In to add comment