oibo8x / subsonicproject

Automatically exported from code.google.com/p/subsonicproject
0 stars 0 forks source link

Update SetExpression with tablecolumn or string problem... #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello All,

I try the following code and there is an exception

String threads = Forum.Columns.Threads + " + " + 1.ToString();
String posts = Forum.Columns.Posts + " + " + 1.ToString();

DB.Update<Forum>()
.SetExpression(Forum.ThreadsColumn).EqualTo(threads)
.SetExpression(Forum.Columns.Posts).EqualTo(posts)
.Where(Forum.ForumIDColumn).IsEqualTo(62)
.Execute();

SubSonic.SqlQueryException : Failed to convert parameter value from a
String to a Int32.

After I digg into the code....
I think the problem relate to update.cs

=========
public Setting SetExpression(TableSchema.TableColumn col)
{
    return CreateSetting(col.ColumnName, col.DataType, true);
}
===========
For above example, I use ".SetExpression(Forum.ThreadsColumn).EqualTo(threads)"
The type of Forum.ThreadsColumn is Int32.  Therefore, it  will  generates
DBType equal  to Int32
I think that's wrong.....expression always should be string type, right?

So, the correct code should be as following

public Setting SetExpression(TableSchema.TableColumn col)
{
    return CreateSetting(col.ColumnName, DbType.AnsiString, true);

}

Comments?

What version of the product are you using? On what operating system?
V2.1 Final

Original issue reported on code.google.com by jasonso...@gmail.com on 24 Jul 2008 at 4:26

GoogleCodeExporter commented 9 years ago
If you have a question please post to our forums or our StackOverflow tag 
(SubSonic).

In this case this isn't a bug - SetExpression is for you to pass in something 
like:

SetExpression(TableSchema.TableColumn col).EqualTo("MyOtherColumn * 12")

It needs a string in order to function - I need to doc this...

Original comment by robcon...@gmail.com on 8 Apr 2009 at 3:28