5. November 2010 01:58
Tonight I ran into a weird problem that I haven’t seen before. I was getting an entity back from a query, changing some values, and calling the DataContext.SubmitChanges() and the database was not being updated. The code ran fine without any exceptions. Weird! I decided to fire up SQL Server Profiler and see what queries were being executed and to my surprise Linq To Sql (L2S) was not executing anything. After 5 minutes of thinking why that would be the case the light bulb turned on! I didn’t have a Primary Key set on the table. Why I didn’t have one it’s not important other than this table didn’t really need it as far as SQL Server is concerned. It turns out that L2S does need one in order to generate updates.