You need to set UpdateCheck for all properties of the Article class, except the primary key (click on the class property in the LINQ2SQL constructor and switch to the "Tool Properties" window) to "Never" (not sure if WhenChanged may work too) and experiment with it!).
This will force LINQ2SQL to use
UPDATE ... SET ... WHERE ID = @2
instead of the long version with all the columns in the WHERE clause:
UPDATE ... SET ... WHERE ID = @2 AND ItemsInStock = @1 AND SomeOtherColumn = @3 AND...
Now you can use code like
context.Articles.Attach(article , new Article { ID = articleID, ItemsInStock = -1 } ); context.SubmitChanges();
Basically, you indicate that only the ItemsInStock property has changed - other details should have the same default value, of course, the article identifier.
NOTE. You do not need to retrieve the article before this.
liggett78
source share