Linq exception

If you have done much programming with Linq and using the relationships between tables, you may come across the following exception:

System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException
Operation is not valid due to the current state of the object.

This is basically telling you that you have a Relationship between two tables and you are trying to update the link to point to something else.

In my case, I had something like:

Table1

ID
nvarchar

Table2

ID
Table1ID

And I was setting Table1ID, which maps to Table1’s ID to 0.  So if you want to delete an entry, just remove the row in Table1 and Table2 will be updated with the delete.

Published 25 February 09 10:44 by Tom
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Click & Solve » Linq exception said on February 25, 2009 11:26 AM:

PingBack from http://www.clickandsolve.com/?p=14363

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker