开发者

How can I transfer an NHibernate PersistentGenericSet over WCF

开发者 https://www.devze.com 2022-12-25 08:58 出处:网络
I\'m trying to send objects retrieved by NHibernate over WCF, but whenever a have a property of ICollection I get an exception.

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

When NHibernate gets the data from the database this property is intitialized with an instan开发者_如何学Pythonce of PersistentGenericSet.

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

-or-

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


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.

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.

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.

Edit

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.

0

精彩评论

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