7

I am trying to do the equivalent of an SQL UPDATE with C# statements in linqpad but the data doesn't change and I'm not sure to even debug it further to figure out why. The User table is pretty standard with just a string to store Sid.

var usersWithSid = from u in Users where u.Sid != null select u;
foreach(var u in usersWithSid) {
    u.Sid = "S-1-5-21-3812666658-2998621725-2245962016-6618";
}
SubmitChanges();
usersWithSid.Dump();

Most of the examples I have found seem to only update one record at a time. Why doesn't this work?

Kevin
  • 4,567
  • 1
  • 28
  • 36
  • This exact thing works fine for me. I'd suspect something screwy on your DB column definition (you didn't specify what kind of string the column is- perhaps something fixed-length or off row?). Mine is a varchar(200), and the update works exactly as expected. – nitzmahone Aug 30 '12 at 20:42
  • Mine is an NVarchar(100) – Kevin Aug 30 '12 at 20:44

1 Answers1

5

Do you have a primary key defined on the table? The updates will silently fail if you don't.

nitzmahone
  • 13,720
  • 2
  • 36
  • 39