2

This question was asked back in October (unable-to-cast-object-of-type-nhibernate-collection-generic-persistentgenericbag). Basically, I have a POCO that has a one-to-many relationship modeled by a List<ChildType>. When you try to get it/save it in NHibernate you get a type cast exception saying it's trying to cast from NHibernate.Collection.Generic.PersistentGenericBag to the List, and can't do it.

Mauricio Scheffer answered that you have to define your POCO as an IList<> rather than a List<>, and answer I've also found other places.

My problem is that the POCO also has to be XmlSerializable, and Xml does not know how to serialize an interface.

Is there any other way to solve this problem than creating a completely duplicate data transfer object and mapping between them? Also, it seems to me that this would be a relatively common problem. Can't NHibernate just provide an appropriate TypeCast operator?

Community
  • 1
  • 1
Dave Hanna
  • 2,491
  • 3
  • 32
  • 52

1 Answers1

0

Hi I answered this question and I solved it using Dozer framework you can view the solution at NHibernate: How do I XmlSerialize an ISet<T>?

Community
  • 1
  • 1
user1393631
  • 91
  • 2
  • 7