NHibernate:无法投射 PersistentBag

发布于 2024-08-19 19:10:04 字数 657 浏览 2 评论 0原文

这个问题早在十月份就被问过(unable-to-强制转换对象类型-nhibernate-collection-generic-persistentgenericbag)。基本上,我有一个 POCO,它具有由 List建模的一对多关系。当您尝试在 NHibernate 中获取/保存它时,您会收到一个类型转换异常,表示它正在尝试从 NHibernate.Collection.Generic.PersistentGenericBag 转换到列表,但无法执行此操作。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满身野味 2024-08-26 19:10:04

您好,我回答了这个问题,并使用 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>?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文