views:

91

answers:

1

If I try to serialize a linq-to-sql entity, will it by default serialize only the primitive fields or will it try to access the relationship fields as well? If it tries to grab relationship fields, is there a way to override this?

A: 

Which serializer are you using?

  • The DataContractSerializer will include loaded relationships but not those that are not yet loaded / null.
  • The XmlSerializer tend to choke on relationships if they are bidirectional (i.e. entity A points to entity B which in turn points back).
  • The binaryformatter ... I never got that one to work properly with L2S entity objects having relationships to other entities. Long time since I tried though, so maybe I just did something wrong...
KristoferA - Huagati.com
I haven't decided on a serializer yet, I was hoping that one of them had the option or by default didn't try at all to traverse the relationship properties. I was going to try System.Xml.Serialization.XmlSerializer first.
Maslow
Ok. The DataContractSerializer is your best bet with L2S generated entity classes. If you want to exclude any already loaded relations, you need to null them out or fiddle with the datamember properties on the association properties...
KristoferA - Huagati.com