LinqToSQL Error : Operation is not valid due to the current state of the object

.net, c#, linq-to-sql

Solution

Grenade's answer actually helped me because I was coming across this exception when attempting to reassign a foreign key. The relationship/constraint was preventing the key from being reassigned.

However, I was able to access the relationship item directly and reassign it, thereby reassigning the foreign key.

product.manufacturer_id = manufacturerID; //This caused the above exception

product.Manufacturer = new Manufacturer(manufacturerID);
//or
product.Manufacturer = OtherManufacturer;

Problem

During an update command I received the following error: Operation is not valid due to the current state of the object I tried to remove one column from the update command and it works fine. This column is a FK that is similar to the other FK that works fine. This is the code that executes the update: ``` ti.NumeroTitolo = titolo.Numero; ti.RKTipoTitoloGenereTitolo = titolo.RkTipoTitoloGenereTitolo; ti.RKBanca = titolo.RkBanca; ti.DataScadenza = titolo.DataScadenza; ti.RKTipoEsito = titolo.RkTipoEsito; ti.ImportoTitolo = titolo.ImportoTitolo; _dc.SubmitChanges(); ```

Original source