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.