Timmay Timmay - 4 months ago 10
SQL Question

Updating just one column value using LINQ

Suppose I have the ID of a column in a table and I want to increment one of it's column values by 1. How should I go about this.

This is what I already have.
Table has 3 properties, (id, category, value)

var col1= db.columns.Where(w => w.category.Equals("Cars"));


I want to increment the value in the table which has category "Cars" by 1.
What is the LINQ Query for this.

A similar question may have been asked before but no answer I have seen seems satisfactory enough.

Answer
var col1= db.columns.Where(w => w.category.Equals("Cars"));
foreach (var item in col1)
{
    item.SPECIFIC_PROPERTY = "VALUE";
}

try
{
    db.SubmitChanges();
}
catch (Exception ex)
{
   //Handle ex
}