如何通过WCF传输NHibernate PersistentGenericSet [英] How can I transfer an NHibernate PersistentGenericSet over WCF

查看:101
本文介绍了如何通过WCF传输NHibernate PersistentGenericSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过WCF发送NHibernate检索到的对象,但是只要具有ICollection的属性,我都会遇到异常.

I'm trying to send objects retrieved by NHibernate over WCF, but whenever a have a property of ICollection I get an exception.

当NHibernate从数据库中获取数据时,将使用PersistentGenericSet实例来初始化此属性.

When NHibernate gets the data from the database this property is intitialized with an instance of PersistentGenericSet.

是否可以通过WCF发送PersistentGenericSet?

Is there a way I can send a PersistentGenericSet over WCF?

-或-

是否可以通过某种方式使NHibernate用其他类型初始化这些属性?

Is there some way making NHibernate initialize these properties with another type?

推荐答案

PersistentGenericSet是NHibernate的一部分(用于跟踪集合中的更改).它基于ISet接口和Iesi.Collections中的类,该类用于填补.Net框架中的空白,因为没有Set类型.我想WCF在序列化此类型时遇到问题.

The PersistentGenericSet is part of NHibernate (used to track changes in collections). It is based on the ISet interface and classes from Iesi.Collections, which was used to fill a gap in the .Net framework as there isn't a Set type. I guess that WCF has a problem serializing this type.

一个快速解决方案是将NHibernate映射更改为使用Bag而不是Set.然后,您可以在班级中使用普通的IList<T>代替Set<T>.

A quick fix is to change your NHibernate mappings to use a Bag instead of a Set. Then you can use a normal IList<T> instead of Set<T> in your classes w.

一个更好的解决方案是创建一个远程外观,它发送 Automapper 是一个很好的工具,将有助于映射过程.

A better solution is to create a remote facade which sends DTOs to your WCF endpoints. This will allow you to keep the interface of your internal types separate from those exposed as remote services. Jimmy Bogards Automapper is a great tool which will help with the mapping process.

重新阅读问题后,我环顾了一下,并发现了这个文章,其中介绍了一种通过WCF发送NHibernate集合的解决方法. David Brion已很好地跟进文章.

After re-reading the problem I had a look around the and came across this article which describes a workaround for sending NHibernate collections over WCF. David Brion has written a good follow up article.

这篇关于如何通过WCF传输NHibernate PersistentGenericSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆