GetChangeSet throws exception when FK has been nulled out - by John Rusk

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 343378 Comments
Status Closed Workarounds
Type Bug Repros 15
Opened 5/11/2008 1:11:57 PM
Access Restriction Public


If a non-nullable relationship is nulled out, then I call GetChangeSet, I get an error like this:

"An attempt was made to remove a relationship between a X and a Y. However, one of the relationship's foreign keys (X.A) cannot be set to null"

This is a real nuisance. Yes, I can see why this kind of error must happen on SubmitChanges, but I'm not trying to submit any changes.  I'm just trying to find out which objects the user has edited (so I can run some validation on them, as it happens).  I would think that the system could tell me which objects have been edited regardless of whether or not they satisfy mandatory relationships.
Sign in to post a comment.
Posted by Microsoft on 2/25/2009 at 4:40 PM

Thank you for taking the time to send this feedback and bug report. We have reviewed the issue and confirmed the behavior, but we will not be fixing this in the next release of LINQ to SQL.

LINQ to SQL Team
Posted by Eivind Tjore on 9/29/2008 at 1:37 AM
I agree, this is a very important bug.
To bad if a thing like this should be the showstopper for using the otherwise excellent linq-to-sql
Posted by KarloX2 on 9/20/2008 at 1:33 AM
I too think this bug is very important. To me, it's nearly a show stopper. Please, MS, provide some feedback about what you're doing to address this!! All the workarounds posted here do not help!!

I've posted a feature request for a HasChanges property

because I think that many people just want to check for pending updates.

Posted by John Rusk on 6/26/2008 at 7:24 PM
I don't know how to download the attachments. I uploaded them, but can't see how to download them. Maybe only Microsoft staff can download them???? Anyway, the code is based on the code in the discussion forum (link shown above)
Posted by LenaGuselnikova on 6/24/2008 at 6:37 AM
Excuse me.
How download attachments: and
I don't see a button for download. :-(
Posted by timlajaunie on 6/20/2008 at 1:29 PM
I sure hope this is resolved with SP1. The GetChangeSet function is very nice for displaying changes (from a general standpoint).
Posted by John Rusk on 6/10/2008 at 1:58 PM
Any update on this bug? Does the attached code reproduce the bug at Microsoft?
Posted by John Rusk on 5/25/2008 at 2:46 PM
I have now attached the source and binary of a test exe which reproduces the bug. Note: the repro successfuly reproduces the bug on my machine. It is based on code provided by Microsoft, as discussed in the latter portion of this thread:

It may not work on all machines at Microsoft, but I can assure you it does reproduce the bug on my machine! ;-)
Posted by John Rusk on 5/14/2008 at 2:59 PM
Steps to reproduce now posted at the forums URL above. Basically the steps are: set relationship's entity (e.g. set order.Product), call GetChangeSet, clear it by setting to null, call GetChangeSet again. Blows up on the second call.

Posted by Microsoft on 5/12/2008 at 2:28 AM
Thank you for your feedback. We are currently investigating. The investigation process normally takes 7-14 days. If this issue is urgent, please contact support directly (see

If at any time your issue is closed unsatisfactorily, you may edit your issue via Connect and change the status to “Active.”

Thank you,
Visual Studio Product Team
Posted by John Rusk on 5/11/2008 at 1:16 PM
PS: This bug is discussed here: