Note that there are some explanatory texts on larger screens.

plurals
  1. POThe member 'X' was changed to be inconsistent with the association member 'Y'
    text
    copied!<p>I get this error if I follow these steps:</p> <ol> <li>Change property Y of an object (an associated entity property)</li> <li>Attempt to submit changes</li> <li>At this point the value of Y and the value of X (the underlying key) are not in agreement -- LINQ to SQL apparently doesn't synchronize these until GetChangeSet is called.</li> <li>An expected error occurs due to some business logic or database level constraint during the update operation.</li> <li>At this point the value of Y is in agreement with X because GetChangeSet was called.</li> <li>Change the value of Y to Nothing (aka null).</li> <li>Call GetChangeSet.</li> </ol> <p>The error occurs on the last step because the value of X and the original value of X (returned by GetOriginalEntityState) are different, and the new value does not agree with Y? Is that why? Is this a bug in LINQ to SQL. Must be because I don't see the same behavior if I change Y to another (non-null) value instead during step 5. What's the right way around this? I can see a few ways:</p> <ol> <li>Discard the DataContext when an error occurs and leave the UI as-is. I don't like this because then optimistic cocurrency change conflicts cannot be detected. The new context doesn't have the original values in it that were populated at the same time the UI was populated, so if the UI has any stale values in it, they will cause data in the database to revert.</li> <li>Refresh the datacontext (OverwriteCurrent) and leave the UI as-is. I don't like this for the same reason as #1.</li> <li>Refresh the datacontext (OverwriteCurrent) and re-populate the UI. I don't like this because then the error message just presented to the user does not show the user the error they made and allow them to correct it. It also discards all the other changes the user may have made.</li> <li>When the error occurs, explicitly retrieve the key for Y that corresponds to the original value of X and reset Y, then call GetChangeSet to re-synchronize X (X is read-only or private so I can't reset it directly). This seems to work, but seems like a hack, and may require lots of code for other similar errors.</li> </ol> <p>Is there a better solution. Is this something that should be reported?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload