开发者

NHibernate and XML Serialization with IList<T>

I've recently started using NHibernate, and on the whole like it a lot.

Until I ran into a problem with needing to serialize to XML and back.

I have a class that has a many to many relationship, so have an IList in the parent class to hold the list of child objects.

Class parentClass开发者_运维问答{
  IList<childClass> childList;

  string varA;
  string varB;
}

I need to be able to serialize this to XML and back, but obviously the IList prevents me from doing this, due to NHibernate wanting to control the concrete implementation of the IList, in this case using a Bag.

Ideally I want to avoid having separate DTOs just to replace the list, as my main motivation for using NHibernate was being able to use it with POCOs and not have to cook up a nasty framework around it.

I'm aware of being able to take control of the serialization process with ISerializable, but again that seems to negate the point of using NHibernate in the first place to reduce complexity.

Also the XML needs to remain 'plain' as it is used to inter-operate with third parties.

What's the best way to work around this constraint?

Thanks!


See:

C# Castle ActiveRecord: How to elegantly (XML) serialize ActiveRecord objects?

How do I serialize all properties of an NHibernate-mapped object?

NHibernate and WCF Serialization(Unidirectional)

JSON.NET and nHibernate Lazy Loading of Collections

Which .NET JSON serializers can deal with NHibernate proxy objects?

DTOs vs Serializing Persisted Entities

Returning NHibernate mapping classes from WCF services

Bottom line: use DTOs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜