NHibernate.Generics Update

time to read 2 min | 366 words

Okay, it's about time that I update this thing. Now it's properly versions in the NQA repository, and you can reach it via: svn://svn.berlios.de/nqa/NHibernate.Generics/ or via: http://svn.berlios.de/wsvn/nqa/NHibernate.Generics/.

There are some new stuff there as well:

  • Tests for ManyToMany, which a lot of people requested.
    • Pay attention to many-to-many, lazy loading, and the edge case I talk about here.
    • I added an overload for this, and you must use this overload when you are creating the collection that will be the authoritative source (inverse=false, in the mapping). Check the User class in the tests for the detials.
  • Proper handling of Clear() on EntitySet
  • Introducing the AllowModification, and this one require some explenation. I found myself needing to modify the EntitySet<T> from within the action for adding and removing items. This caused problems, because ordinarily this would mean that I would get an infinite loop, but no worries, you can see how I solved it below (which is why I need the DisposableAction for). There is a similar property for the EntityRef<T>.
   1:  //Require a class member variable, can't use a local
   2:  //variable, because of delegates rules.
   3:  _posts = new EntitySet<Post>(
   4:  delegate(Post p)
   5:  {
   6:      using (_posts.AllowModifications)
   7:      {
   8:          _posts.Add(new Post("Duplicate"));
   9:      }
  10:  }, null);
  11:  _posts.Add(new Post("Original"));
  12:  Assert.AreEqual(2, _posts.Count);

That is all for now, I think. I changed the download to be just the compiled dll (you can get the source from the repository above). Most important of them all, I updated the documentation with the new stuff.

One interesting tidbit, so far I had over 950 dowloads of NHibernate Generics!