In LinqToSql, it is lovely easy to load a row, change a column, and submit the changes to the database:
using (MyDataContext wdc = new MyDataContext())
{
Article article = wdc.Article.First(p => p.ID == id);
article.ItemsInStock = itemsinstock;
wdc.SubmitChanges();
}
The only drawback: Article is huge. To load the entire article, just to update one column is way overkill and slows down my app significantly.
Is there a way to update a single column using LINQ, without having to load the entire row?
Right now I revert to using ExecuteCommand where speed is of essence, but this is ugly and error prone:
wdc.ExecuteCommand("UPDATE Article SET ItemsInStock = @1 WHERE ID = @2", itemsinstock,id);
ligget78 gave me another idea how to make an update of a single column:
Create a new DataContext just for this kind of update, and only include the needed columns into this DataContext.
This way the unneeded columns will not even be loaded, and of course not sent back to the database.