Is this LinqToSQL bug ever going to be fixed?
-
Wednesday, January 09, 2013 4:50 PM
At the risk of repeating other threads, I've just found out that my LinqToSQL database cannot update a non-identity primary key int field in my database. I'm writing a DotNet 4.0 web app in VS2012.
Deleting a record is not an option since this non-identity field is a cascadable foreign key for a detail table.
This data structure works fine in the database itself. Why can't LinqToSQL handle it?
(To me this shortcoming certainly seems to qualify as a bug.)
All Replies
-
Wednesday, January 09, 2013 7:04 PM
SQL tables without primary keys are a bad idea. I could give you lots of examples of why this is so, but Linq follows that idea and will not generate the code to update/insert/remove table items without a PK.
All that said I am not sure what you mean "cannot update a non-identity primary key".
LS
Lloyd Sheen
-
Wednesday, January 09, 2013 9:05 PM
The primary key is a must and needed ONLY when you use data visualization layer or ORM such as LinqToSQL.
even if your sql table may not have primary key set, you must set a primary key manually in the Linq diagram, that will enable LinqToSQL to generate the code required for update/insert/delete.
Blog: http://samir-ibrahim.blogspot.com/
- Edited by Samir Ibrahim Wednesday, January 09, 2013 9:05 PM
-
Wednesday, January 23, 2013 9:18 PM
My apologies for not responding sooner.
I should clarify that my table does have a primary int key. It's just not an automatically incrementing Identity field.
However, even though LinqToSql cannot handle this situation automatically, I found out that it was a relatively simple matter to do the update of the key through a stored procedure, which was easily callable through LinqToSQL. Problem solved.
Of course this is a bit more cumbersome than usual but I don't anticipate having this situation very often.
- Proposed As Answer by SilentJealousy Friday, January 25, 2013 7:43 AM
- Marked As Answer by Alexander SunModerator Wednesday, January 30, 2013 7:54 AM

