none
Efficient binary serializer for Linq to SQL object graphs RRS feed

  • Question

  • Is anyone aware of an efficient binary serializer for Linq to SQL entities?  I am using VS2010 (VB) with .net 4.0 and successfully used the XLMserializer, but because of the XML tags, the file it produces is almost 1MB for a 20K object.  I have not been successful in getting the System.Runtime.Serialization.Formatters.Binary to work with my Linq objects, even after decorating the classes as serializable and the dbml as unidirectional.

    I read about the binary JSON serialization and heard that it is  relatively efficient, but cannot find any examples of how to use it with my Linq objects.  I am looking for something which will serialize both primary and relational data.

    Thanks!


    -BGood
    Tuesday, December 14, 2010 4:04 AM

Answers

  • The serializers that work best with Linq-to-SQL entity classes and object graphs are the DataContractSerializer and the DataContractJsonSerializer. Set the serialization mode property in the L2S designer to Unidirectional to decorate the classes with the attributes needed by those serializers.

    To make the output more compact, pass the serialized data through a GZipStream to compress/decompress.

     


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    • Marked as answer by BGood Tuesday, December 14, 2010 10:41 PM
    Tuesday, December 14, 2010 5:25 AM
    Answerer

All replies

  • The serializers that work best with Linq-to-SQL entity classes and object graphs are the DataContractSerializer and the DataContractJsonSerializer. Set the serialization mode property in the L2S designer to Unidirectional to decorate the classes with the attributes needed by those serializers.

    To make the output more compact, pass the serialized data through a GZipStream to compress/decompress.

     


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    • Marked as answer by BGood Tuesday, December 14, 2010 10:41 PM
    Tuesday, December 14, 2010 5:25 AM
    Answerer
  • Thanks, KristoferA. 

    I have been working for several days trying to get the binaryformatter to work directly with my Linq classes and have not been successful.  I really like the efficiency of the binaryformatter relative to json and especially XML.

    I ended up translating and debugging http://www.codeproject.com/KB/linq/linqsqlserialization.aspx to VB so I could work with the binaryformatter and finally got it working by combining multiple SerializedEntitity memorystreams, one for each related object in the graph, into a single filestream.

    Thanks again for your suggestions.


    -BGood
    Tuesday, December 14, 2010 10:48 PM