Hibernate version:1.0.2
My Context
I use WCF to send NHibernate Bags over the wire, which means the collection is serialized/deserialized by the DataContractSerializer (from the System.Runtime.Serialization namespace in the May CTP of WinFx)
Now I already know that this breaks at least one of the 4 tenants of SOA, but in my scenario it's the simplest thing that works, well, it used to work in the Feb CTP....
My Issue
Now if you try this in the latest WCF bits you'll get the following exception message:
Type 'NHibernate.Collection.PersistentCollection' is an invalid collection type since it does not have a valid Add method with parameter of type 'System.Object'
(I've posted the original problem at
http://forums.microsoft.com/MSDN/ShowPo ... 9&SiteID=1)
I've recently discovered that the May bits of the DataContractSerializer (and probably the RTM bits as well) require collection types that implement ICollection or IEnumerator to contain an Add method that takes a System.Object as a parameter and also requires it to have a default constructor (they can both be private).
My Solution
So, to resolve this I had to modify the source of the Nhibernate.Collection.PersistentCollection to have the private Add method and I had to modify the Nhibernate.Collection.Bag to have a default constructor.
I haven’t tried it but I assume that the 1.2.0 PersistentBag would also need a default constructor if it were to be used to hold data for a WCF message.
My Recommendation
It sure would be nice if the 1.2.0 version the collections were made to be WCF friendly by having at a minimum default private constructor and private a Add method. Now, there may be a million reasons why this is a terrible idea that I haven’t considered, but I just thought I'd throw this idea out there...
Greg Banister