0

I have a table and I need to update 2 rows at a time.

My SQL query will look like this:

UPDATE tablename SET columnname=value WHERE tablename.id in (1,2)

I need the same in LINQ.

Thanks in advance.

Santosh
  • 2,355
  • 10
  • 41
  • 64
  • 1
    its may be help to u. http://stackoverflow.com/questions/10314552/how-to-update-the-multiple-rows-at-a-time-using-linq-to-sql thank you –  Feb 11 '15 at 12:38
  • 2
    already asked http://stackoverflow.com/a/10314666/17447 with a very detailed answer. – naveen Feb 11 '15 at 12:38
  • LINQ is a *query* language, not an update language. – Gert Arnold Feb 14 '15 at 10:18

1 Answers1

1

There is no such thing in LINQ to SQL. It will Always update one row at a time.

Of course, you can do a

foreach (var key in keys)
{
var r = db.Table.Single(i=>i.ID == key);
r.xyz = value;
}
db.submitchanges()

But essentially this will update each row with a single update statement. In a transaction, nonetheless so it will achieve the same as your update statement but with a significant performance penalty depending on the number of records

Pleun
  • 8,856
  • 2
  • 30
  • 50