Fervelas
Fervelas

Reputation: 73

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 suitable way to make a reference to the same field with the Setting object.

Any help on this will be greatly appreciated.

Regards,

Fernando

Upvotes: 3

Views: 1179

Answers (3)

Krunal
Krunal

Reputation: 3541

You can execute this query using QueryCommand object of subsonic.

You can find similar samples over here link and link

Upvotes: 2

Fervelas
Fervelas

Reputation: 73

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.

Upvotes: 1

user1151
user1151

Reputation:

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.

Upvotes: 1

Related Questions