开发者

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

开发者 https://www.devze.com 2022-12-16 20:01 出处:网络
During an update command I received the following 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; 
        开发者_JAVA技巧        ti.ImportoTitolo = titolo.ImportoTitolo;

                _dc.SubmitChanges();


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;


The problem may be caused by a relationship or other constraint. For example if you are attempting to drop a row who's Id is referenced by some other table with a relationship. Perhaps if you post the SQL or LINQ query that is giving the error we can help you more.


I was getting the same error trying to create a subscription. Found this post:

I was also having this issue. I found a good post that told how to add a key to the web.config file in the folder C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportManager.

I had to remove the <> to make it show.

add key="aspnet:MaxHttpCollectionKeys" value="10000"

http://social.msdn.microsoft.com/Forums/ar-SA/sqlreportingservices/thread/c9d4431a-0d71-4782-8f38-4fb4d5b7a829

0

精彩评论

暂无评论...
验证码 换一张
取 消