Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get linqpad to update columns

Tags:

c#

sql

linqpad

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?

like image 652
Kevin Avatar asked Aug 30 '12 19:08

Kevin


People also ask

How do you update columns?

First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.

How does LINQPad work?

For each query, LINQPad creates a separate server, which a class that runs in its own process and executes the query in isolation. This isolation prevents queries from interfering with each other (or the UI) and allows LINQPad to safely cancel a query without polluting other application domains.


1 Answers

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

like image 142
nitzmahone Avatar answered Oct 24 '22 19:10

nitzmahone