title: Debugging LINQ to SQL SubmitChanges()
body: <p>I am having a really hard time attempting to debug LINQ to SQL and submitting changes.</p>
  
  <p>I have been using <a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx" rel="noreferrer">http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx</a>, which works great for debugging simple queries.</p>
  
  <p>I'm working in the DataContext Class for my project with the following snippet from my application:</p>
  
  <pre><code>JobMaster newJobToCreate = new JobMaster();
  newJobToCreate.JobID = 9999
  newJobToCreate.ProjectID = "New Project";
  this.UpdateJobMaster(newJobToCreate);
  this.SubmitChanges();
  </code></pre>
  
  <p>I will catch some very odd exceptions when I run this.SubmitChanges;</p>
  
  <pre><code>Index was outside the bounds of the array.
  </code></pre>
  
  <p>The stack trace goes places I cannot step into:</p>
  
  <pre><code>at System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2&amp; k)
     at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
     at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
     at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
     at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
     at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
     at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
     at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
     at System.Data.Linq.DataContext.SubmitChanges()
     at JobTrakDataContext.CreateNewJob(NewJob job, String userName) in D:\JobTrakDataContext.cs:line 1119
  </code></pre>
  
  <p>Does anyone have any tools or techniques they use?  Am I missing something simple?</p>
  
  <p><strong>EDIT</strong>:
  I've setup .net debugging using Slace's suggestion, however the .net 3.5 code is not yet available: <a href="http://referencesource.microsoft.com/netframework.aspx" rel="noreferrer">http://referencesource.microsoft.com/netframework.aspx</a></p>
  
  <p><strong>EDIT2</strong>:
  I've changed to InsertOnSubmit as per sirrocco's suggestion, still getting the same error.</p>
  
  <p><strong>EDIT3:</strong>
  I've implemented Sam's suggestions trying to log the SQL generated and to catch the ChangeExceptoinException.  These suggestions do not shed any more light, I'm never actually getting to generate SQL when my exception is being thrown.</p>
  
  <p><strong>EDIT4:</strong>
  I found an answer that works for me below.  Its just a theory but it has fixed my current issue.</p>