title: UPDATE operation - Operation is not valid due to the current state of the object
body: <p>I have two tables that are linked by a foreign key reference, let's call them RX and program.
  I have this method that tries to change the program id in the RX table, which is an FKR to the program id field in the program table. Whenever I try to do this, I get an</p>
  
  <blockquote>
    <p>"Operation is not valid due to the current state of the object"</p>
  </blockquote>
  
  <p>Which gets fired on: </p>
  
  <p><code>System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();</code>
  What am I doing wrong here? </p>
  
  <p>The offending code snippet and the database field definition are below. Code:</p>
  
  <pre><code>    public void ChangeProgram(int programId, DbDataContext dc)
      {
          //var programId = ddlPrograms.SelectedValue.ToInteger(0);
          if (programId &gt; 0)
          {
              var referral = PrescriptionManager.GetReferral(dc, _view.RxID);
              if (referral != null &amp;&amp; referral.AspnRx.ProgramID != programId)
              {
                  try
                  {
                      referral.ProgramID = dc.PROGRAMs.Single(p =&gt; p.ProgramID == programId).ToString().ToInteger(1);
                  }
                  catch (ForeignKeyReferenceAlreadyHasValueException exception)
                  {
                      _view.ChangeProgramSuccess = false;
                  }   
  </code></pre>
  
  <p>Database field definition:</p>
  
  <pre><code>    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProgramID", DbType="Int")]
      public System.Nullable&lt;int&gt; ProgramID
      {
          get
          {
              return this._ProgramID;
          }
          set
          {
              if ((this._ProgramID != value))
              {
                  if (this._PROGRAM.HasLoadedOrAssignedValue)
                  {
                      throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                  }
                  this.OnProgramIDChanging(value);
                  this.SendPropertyChanging();
                  this._ProgramID = value;
                  this.SendPropertyChanged("ProgramID");
                  this.OnProgramIDChanged();
              }
          }
      }
  </code></pre>