开发者

NHibernate: Unable to cast PersistentBag

开发者 https://www.devze.com 2022-12-18 17:33 出处:网络
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 Li

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>?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号