Why is it not inserting? ASP.NET LINQ 2 SQL

December 24, 2012

While using an ORM system like LINQ 2 SQL, you may notice some unexpected results without explanation why. This is frustrating since Visual Studio does an excellent job relating errors and mistakes to you before you even build your solution.

Recently I was trying to insert a new row but when I submitted changes, it wouldn’t save in the database. Even stranger was that when I viewed the change set before submitting, there were 0 Inserts. I wasn’t able to come up with any error, exceptions, or warnings on why it wasn’t working but eventually I did find the problem. It was a simple oversight in my DBML configuration for the table. My unique id for the table did not have it set to Primary Key in the DBML file. Rookie mistake, but terribly compounded by the lack of a message telling me the issue.

Other things to look out for is to make sure all columns match in regards to allowing nulls. This will generate an error if they do not but it is not very descriptive to what the issue actually is.

Hopefully these tips saves some hours for you.

Stay in Touch!

Subscribe to our newsletter.

Solutions Architecture

browse through our blog articles

Blog Archive