SubSonic equivalent of an SQL update
I'm wondering if the following SQL update query is possible using the equivalent SubSonic commands:
UPDATE MYTABLE SET MYFIELD = MYFIELD + 3 WHERE ANOTHERFIELD = ANOTHERVALUE
I couldn't find a suita开发者_运维问答ble way to make a reference to the same field with the Setting object.
Any help on this will be greatly appreciated.
Regards,
Fernando
You can execute this query using QueryCommand object of subsonic.
You can find similar samples over here link and link
Yes - you can use "UpdateExpression" - it's a string value that you pass in with the "simple" query tool. I don't have the code or the sample in front of me - it might be "SetExpression" but it allows you to update using a string like you've entered here.
I did a test using what you said on SetExpression() but somehow I'm not convinced I'm using it right.... it works but it feels (and looks) kinda funny you know?
int count = new Update(MyTable.Schema).SetExpression("MyField").EqualTo("MyField + 20")
.Where(....)
As I said, the update worked but I'm not sure if that's the intended way of doing it, and if it is (or even if it isn't), then how could I use a parameter instead of hard-coding the value in the expression.
精彩评论