1

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.

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

+1 Yes, use the DataContractSerializer... sample: social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/…
Be careful that DataContractSerializer doesn't serialize fields that are part of the implementation of the objects. It does so for Entity Framework types in .NET 3.5, and I think I saw it do the same for L2S.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.