Reputation: 4184
I am working on an Audit Log for an application that uses Linq-To-Sql. I want to serialise an object to stores its values in a XML column in a SQL Server databse.
My problem is that when I try to serialize a Linq-To-Sql obejct that it attempts to serialize all associated entities and entity sets.
My first attempt at a solution was to create seperate class tos tore what I need to serialize and then pass this to an XmlSerializer.
I suppose what I really want to know is how to get the XmlSerializer to ignore certain types of properties - E.g entities and entity sets.
Would I have to write my own XmlSerializer?
All and any advice would be aprreciated.
Upvotes: 1
Views: 1342
Reputation: 117250
You need to use the DataContractSerializer
, but this will still serialize a partial object graph.
The better solution is to generate your own Linq2SQL classes and apply the XmlIgnore/DataMember
attributes (depending on whether you use XmlSerializer
or DataContractSerializer
).
Upvotes: 1