views:

190

answers:

2

I'm using NHibernate to administer my entities, and to have lazy loading enabled I need to make my properties return an IList<>. Problem is that .NET throws an exception as it can't serialize an interface when I'm trying to pass the entity. This makes perfect sense.

What I need to know is how I can control which fields to serialize, and which not to? My best bet so far is to work around this problem by copying the contents of IList<> into a List<> before serializing the object, but to do that I need to tell .NET that I don't want the IList<> property serialized :)

A: 

MSDN has an area on Serializing Objects, but what you want is Selective Serialization. So basically, you can mark any property you don't want serialized with the attribute, [NonSerialized]. There is an example in the second link.

Mr. Will
Thanks a lot .. You helped me a lot with those resources, however the correct attribute was System.Xml.Serialization.XmlIgnore , which I'll post in a new answer for further reference.
cwap
Your welcome. I should have asked if you were doing binary or XML serialization. It has been a long time since I did serialization in .NET.
Mr. Will
I might be wrong here, but since I'm using a webservice, ain't it supposed to be soap, which in turn means that it needs to be XML-serialization? :P
cwap
Yes, you need XML serialization. This is not the answer to your question.
John Saunders
A: 

Just wanted to let you guys know that I found the answer to be the [System.Xml.Serialization.XmlIgnore] attribute :)

cwap