NHibernate:无法投射 PersistentBag
这个问题早在十月份就被问过(unable-to-强制转换对象类型-nhibernate-collection-generic-persistentgenericbag)。基本上,我有一个 POCO,它具有由 List
Mauricio Scheffer 回答说,您必须将 POCO 定义为 IList<> 。而不是 List<>,并且回答我还找到了其他地方。
我的问题是 POCO 也必须是 XmlSerialized,而 Xml 不知道如何序列化接口。
除了创建完全重复的数据传输对象并在它们之间进行映射之外,还有其他方法可以解决这个问题吗?另外,在我看来,这将是一个相对常见的问题。 NHibernate 不能提供合适的 TypeCast 运算符吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,我回答了这个问题,并使用 Dozer 框架解决了它?
您可以在以下位置查看解决方案
NHibernate:如何 XmlSerialize ISet
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>?