views:

130

answers:

2

Hi,

I'm learning SubSonic 2.2, and have the following query, but it feels "Wrong" writing my expression ("count + 1") as a string.

Can any experts suggest a better way that this?

            int records = new Update(Wordsfile.Schema)
            .SetExpression(Wordsfile.CountColumn).EqualTo("count + 1")
            .Where(Wordsfile.Columns.WordId).IsEqualTo(wordID)
            .And(Wordsfile.Columns.FileId).IsEqualTo(fileID)
            .Execute();

It's the line: ".SetExpression(Wordsfile.CountColumn).EqualTo("count + 1")".

I've tried: ".SetExpression(Wordsfile.CountColumn).EqualTo(Wordsfile.Columns.Count + 1)", but no joy.

Any suggestions

Thanks!

+1  A: 

Try this instead:

.SetExpression(Wordsfile.CountColumn).EqualTo(Wordsfile.Columns.Count + " + 1")
Adam
Great stuff!That's certainly in improvment, but can anyone think of a way of achieving this without the use of strings?I guess it could also be done with a sub-query, but that seems a bit messy, when using straight sql, the additional query wouldnt be needed.
+1  A: 

Strings aren't so bad and in your case it's pretty simple stuff ("+1"). You could throw a trigger in there :) if you wanted...

Rob Conery