none
Error serialization of Linq to SQL Entities in VS 2008 Beta 2 RRS feed

  • Question

  • Hi All
    I am getting the following error while performing a serialization of a Entity class generated by the LINQ to SQL editor in VS 2008 Beta 2.

    "Type 'System.Data.Linq.ChangeTracker+StandardChangeTracker' in Assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."


    But If I define My own class for the Table with just the Table and Column Mapping, it works fine.

    Does anybody has any examples of serialization of the Linq entities and Anonymous Types? Also examples of WCF with Linq will be greatly appreciated.

    Thanks in advance.
    Regards
    Krushna

    Wednesday, August 22, 2007 4:33 AM

Answers

  • On further thought, based on what you have told me, it sounds like you're attempting to use BinaryFormatter to do your serialization - is this the case?  We emit WCF [DataContract]/[DataMember] serialization attributes which are used by the DataContractSerializer.

    Friday, August 31, 2007 7:10 AM

All replies

  • Hi Krushna,

     

    Anonymous Types only have local scope and cannot be used outside of the method where they where initialised so you will be unable to use these with WCF.

     

    As for Linq entities, I think you need to set the serialisation mode on the DataContext properties. I spoke about it very briefly in this post : http://blog.benhall.me.uk/2007/08/power-of-sqlmetal.html

     

    In the designer, go into the properties for the actual datacontext and there is a dropdown which you can set.

     

    This will then add DataContract and DataMember to the class/property for the objects.

     

    Hope this helps.

     

    Ben

    Wednesday, August 22, 2007 9:58 AM
  • Hi Ben

    Thanks for your response.

     

    I have specified the serialization Mode as Unidirectional and added the attribute [Serializable] for each class generated by the Linq to SQL editor.

     

    Still I am getting the same error.

     

    Please let me know if you need any more info.

    Krushna

    Wednesday, August 22, 2007 5:19 PM
  • I'm also having a problem serializing LINQ to SQL objects. I'm getting a circular reference error even though I've set the serialization mode to unidirectional.

     

    Basically I've got the standard scenario where I have something like a BlogPosts table and then a Comments table. The Comments table contains a PostID and this is apparently causing the circular reference. If anybody can help me get around this, I would be greatly appreciative because I do _not_ want to have to build a non-LINQ-to-SQL model and then a translation layer just so I can get serialization.

     

    Basically I have to serialize LINQ to SQL objects because Astoria doesn't yet work for Orcas Beta 2.

    Thursday, August 23, 2007 6:07 PM
  • Can either of you please provide some more information - both the code for the entity class being serialized as well as the code that is doing the serialization?  I've never seen this error before - thanks.

    Friday, August 31, 2007 7:02 AM
  • On further thought, based on what you have told me, it sounds like you're attempting to use BinaryFormatter to do your serialization - is this the case?  We emit WCF [DataContract]/[DataMember] serialization attributes which are used by the DataContractSerializer.

    Friday, August 31, 2007 7:10 AM