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?
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>?
精彩评论