none
Is there any way to put a C# object into a DataColumn such that its serialization to byte[] happens as part of DataSet serialization? RRS feed

  • Question

  • Some of the rows in our database / DataSets have a column where we store a serialized C# object.  To implement that, we typically define the column as byte[] or as a string... we serialize to XML, stick it in that column, and it gets saved off with the rest of that DataSet.

    The problem with that approach is that those serialized C# objects can get pretty big, and when they do we are generating an object on Large Object Heap, which tend to lead to fragmentation problems (which can lead to premature Out of Memory problems or severe paging performance problems).

    Ideally, we would just stick the C# object in the DataColumn.  And then when the DataSet gets serialized by its WriteXml(XmlWriter), when it goes to write out the value in that C# object column, it would call WriteXml(XmlWriter) on that C# object, serializing it into the stream with the DataSet.  In that way, the serialized version of the C# object never gets written as a whole into a memory object... it just gets streamed out with the rest of the DataSet.

    Is there a way to define a DataColumn to have DataType == Object or DataType == "User-Defined Type" or similar such that its XmlSerializable implementation would call the XmlSerializable implementation fo that object or user-defined type?  Or perhaps some way to specify a "formatter" and a "parser" (kind of like you can with DataBindings) that get invoked during XmlSerialization of the DataSet?  

    Or really, any other option that allows the serialization of the object to occur directly into the XmlWriter when the DataSet gets XmlSerialized?

    Friday, April 5, 2013 7:11 AM

Answers

All replies