I have a set of linq to sql classes and serialized them into JSON using the .NET JavaScriptSerializer.
However, as soon as I add record onto a relating table, serialization throws a "Circular reference exception". Aaarggh!
It's described in detail here.
I have a few options
Has anyone else encountered this? I would really prefer the last option if possible but I don't know how to do this.
Any help is greatly appreciated
The latest version of Json.NET supports serializing circular relationships. Check out Preserving Object References in the help.
Additional link for accepted answer
Json.NET Help, Preserving Object References (with example)
It seems it works fine with LINQ to SQL
James's solution solved part of my problem. I needed to exclude certain List Types within the object. To solve my problem, I just copied the parts of the object I needed. The following is an example.
var DB = new DBDataContext();
var lUsers = new List<User>();
DB.Users.ToList().ForEach(x => lUsers.Add(new User()
{
ID = x.ID,
FIRST_NAME = x.FIRST_NAME
}) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With