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.
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
}
You could use a .ForEach
extension method (you would have to enumerate first), but Linq should be used to query, not to update values.
So use a foreach
foreach (var car in col1) {
car.value +=1;
}
//some method to save changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With