Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();
like image 832
Salvatore Di Fazio Avatar asked Jan 13 '10 16:01

Salvatore Di Fazio


1 Answers

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;
like image 110
Ryan Cannon Avatar answered Oct 01 '22 07:10

Ryan Cannon