What do I lose with Serialization Mode = Unidirectional RRS feed

  • Question

  • My data entities are as follows in a WCF Servicve Library project:

    Web methods were created to return data from the database.  Initially I had Serialzation Mode = None and I couldn't retrieve the User table.  Got that famous "Object graph for type ... contains cycles and cannot be serialized if reference tracking is disabled." error.

    After I set Serialization Mode to Unidirectional, LINQ query on the User table returned the expected results.  However, now a query on the Log table returns most columns as blanks.  Previously a LINQ Query to return data from Log works fine.  My query is pretty simple:

       var rows = (from l in db.Logs orderby l.Time descending select l).Take(10);
       return rows.ToList(); 

    How do I get both types of tables to work?

    I don't quite understand the theoretical explanation on the serialization stuff.  Where can I find suitable material for background reading.


    Monday, December 19, 2011 4:54 PM


All replies

  • I tested by setting Serialization Mode to None and Unidirectional alternately many times, and the result was consistent.

    When Serialization Mode=None, the query on Logs show up all the columns.

    When Serialization Mode=Unidirectional, the query on Logs show data only in the Time and guid columns.  It so happen the Time and guid differ from the other columns in only Auto Generated Value=true but I don't know whether is is related to the cause of the problem.

    What could be wrong?  Thanks.
    • Edited by K.Kong Tuesday, December 20, 2011 6:31 AM
    Tuesday, December 20, 2011 6:31 AM
  • Hi Kong,



    When you set the serialization mode to Unidirectional, the class generated by visual studio gets attributed with DataContract and properties get attributed with DataMember.This makes the class be easily consumed by WCF service. http://weblogs.asp.net/zeeshanhirani/archive/2008/05/04/using-linq-to-sql-with-wcf-service.aspx



    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Wednesday, December 21, 2011 6:50 AM
    Tuesday, December 20, 2011 9:21 AM
  • I solved my problem.

    After changing from None to Unidirectional or vice versa, I must update the service reference on the client side.



    • Edited by K.Kong Wednesday, December 21, 2011 6:06 AM
    • Marked as answer by Alan_chen Wednesday, December 21, 2011 6:50 AM
    Wednesday, December 21, 2011 5:51 AM
  • Sorry guys,

    Perhaps these solution might resolved the issues. but I tried every thing above for the same issue. but still problem is persist. is there any other way ?

    If i changes the .dbml property from None to Unidirectional then my client application receives almost null object. where as few properties of object has values. 

    What should be the reason ?

    Wednesday, June 27, 2012 12:15 PM