title: Circular reference exception when serializing LINQ to SQL classes
body: <p>I have a set of linq to sql classes and serialized them into JSON using the .NET JavaScriptSerializer.</p>
  
  <p>However, as soon as I add record onto a relating table, serialization throws a "Circular reference exception". Aaarggh!</p>
  
  <p>It's described in detail <a href="http://azamsharp.com/Posts/246_Fixing_the_JavaScriptSerializer_Circular_Reference_Exception.aspx" rel="noreferrer">here</a>.</p>
  
  <p>I have a few options</p>
  
  <ul>
  <li>Convert the linq to sql class to a class with no relationships thus avoiding the circular reference</li>
  <li>snip the circular reference by nulling associations - i don't consider this to be a real option</li>
  <li>Use ScriptIgnoreAttribute (somehow). I couldn't easily apply this because the properties are in generated classes and LINQ to SQL doesn't automatically honor buddy classes</li>
  <li>Use JSON.NET and somehow use attributes + buddy classes to stop the serializer trying to walk across relationships.</li>
  </ul>
  
  <p>Has anyone else encountered this? I would really prefer the last option if possible but I don't know how to do this.</p>
  
  <p>Any help is greatly appreciated</p>