For my StackOverflowers colleagues who come up with this question, I will explain what I ended up doing:
In the described case, you need to use the standard .NET serializer (and not ServiceStack): System.Web.Script.Serialization.JavaScriptSerializer . The reason is that you can decorate navigation properties that you do not want the serializer to handle the [ScriptIgnore] attribute.
By the way, you can use ServiceStack.JsonSerializer for deserialization - it's faster than .NET, and you have no problems with the StackOverflowException that I asked about this.
Another problem is how to get Self-Tracking Entities to decorate the corresponding navigation properties with [ScriptIgnore] .
Explanation: Without [ScriptIgnore] , serialization (using the .NET Javascript serializer) will also throw an exception (similar to the problem that causes a StackOverflowException in ServiceStack). We need to eliminate roundness, and this is done using [ScriptIgnore] .
So, I edited the .TT file that came with the ADO.NET Self-Tracking Entity Generator Template and found that it contains [ScriptIgnore] in the appropriate places (if someone needs diff code, write me a comment). Some say it’s bad practice to edit these “external” non-editable files, but damn it solves the problem and this is the only way that does not force me to redesign my entire application (use POCOs instead of STE, use DTO for total, etc.)
@mythz: I do not quite agree with your debate about using DTO - see comments for your answer. I really appreciate your enormous efforts to create a ServiceStack (all modules!) And free use and open source. I just recommend that you either respect the [ScriptIgnore] attribute in your text serializers, or come up with your own attribute. Also, even if you can actually use DTOs, they cannot add navigation properties from the child back to the parent, as they will get a StackOverflowException. I mark your answer as "accepted" because in the end it helped me find my way in this matter.
Ofer Zelig Feb 08 '12 at 20:38 2012-02-08 20:38
source share