LINQ SubmitChanges throws Index Out Of Range Error

You’ll get this if you have Associations in your dbml file which do not reflect the reality of your database.

In my case I was given a dbml file (NOT MY BUG! NOT MY BUG!) that had spurious Associations in them. Like unwanted relatives these must be bought off sent to nunneries deleted.

My database tables are:


I was doing an update on an Order record and got the Index Out Of Range error on SubmitChanges.

Inspecting the dbml, on the advice of this very helpful thread on Stack Overflow and also this one on MSDN LINQ Project General, there were LINQ Associations between Product->Order, Product->Customer and Product->Student.

The last two Associations were spurious. They shouldn’t have been there, specifically, there is no ProductID ForeignKey on Customer and no ProductID ForeignKey on Student either

Once I deleted the spurious, unwanted, grotesque, unneeded, and overall wrong Associations I was once again able to save my Order records during Update, so making the planet safe for Capitalism.


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: