Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a single column in LINQ to SQL

I have a table with multiple columns and I want to update only one column. I'm writing a method that first fetches the record and then updates it by changing the value of the column. Like this:

using (myDC...)
{
  var recordInDB = (from...
                    where ....
                    select r).SingleOrDefault();

  if (recordInDB != null)
  {
     recordInDB.MyColumn = newValue;

     myDC.SubmitChanges();
  }

Is this going to keep all the other columns as they were and only update the one I want to change or is this going to clear all columns and update the column MyColumn with the new value?

like image 366
frenchie Avatar asked Feb 15 '12 14:02

frenchie


1 Answers

This will not change the other columns in your table. Only the one you are updating.

like image 138
ThePaye Avatar answered Nov 04 '22 04:11

ThePaye