tags:

views:

116

answers:

2

I want to update the value of a column in a resultset returned by a linq query.

My code is something like this

var result=from r in db.contents 
select new { match = r.text, id = r.id, index1 = (long)-1}

-- some calculation to find index value --

-- now update r.index=calculatedIndexValue for each record in result

Is this kind of operation possible?

A: 

Don't think so, not without doing a new query (or rewriting the original) so that it returns a non-anonymous type (i.e. a type that is generated using linq 2 sql or entities).

Kurt Schelfthout
+1  A: 

LINQ is a query language - not an editing language. For entity manipulation (changes etc), you need to work with the object-orientated parts of the data-context / entities manager, etc. So basically, you need to either:

  • use a stored procedure instead (or)
  • include the full entity (r) in the output (either by itself, or inside the anon-type); update this object, and call the contexts "save" method (SubmitChanges(), etc).
Marc Gravell