SubSonic3 SetExpression问题
接下来的 SubSonic3 查询给我一个错误:
Db.Update<Tag>()
.SetExpression("Popularity")
.EqualTo("Popularity+1")
.Where<Tag>(x => x.TagId == tagId)
.Execute();
错误:失败:System.FormatException:无法将参数值从字符串转换为 Int32。
生成的sql是可以的,但是参数集合中有两个需要设置的参数。
UPDATE [Tagging].[Tag]
SET Popularity=Popularity+1
WHERE [Tagging].[Tag].[TagId] = @0
参数之一将 @up_Popularity 设置为“Popularity+1”。由于这是设置的第一个参数,因此 sql 会尝试将此字符串“Popularity+1”分配给一个整数。
这是一个错误还是我做错了什么?
Next SubSonic3 query gives me an error:
Db.Update<Tag>()
.SetExpression("Popularity")
.EqualTo("Popularity+1")
.Where<Tag>(x => x.TagId == tagId)
.Execute();
Error: failed: System.FormatException : Failed to convert parameter value from a String to a Int32.
The sql that is generated is ok, but the collection of parameters contains two parameters that need to be set.
UPDATE [Tagging].[Tag]
SET Popularity=Popularity+1
WHERE [Tagging].[Tag].[TagId] = @0
One of the parameters set @up_Popularity to 'Popularity+1'. Since this is the first parameter being set, sql triese to assign this string 'Popularity+1' to an integer.
Is this a bug or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可行......但我认为这是为了批发更新。没有把握。您最好的选择是使用我们的 CodingHorror:
This should work ... but I think it's for wholesale updates. Not sure. Your best bet is to use our CodingHorror:
如果这能起作用的话我会感到惊讶。当我需要将字符串评估为 SQL 的一部分(而不是由 SubSonic)时,我几乎总是最终不得不使用 编码恐怖。
但是,您应该能够通过使用单独的查询来完成此操作。像这样的东西:
I'd be amazed if that was supposed to work. When I need to have a string evaluated as part of the SQL (and not by SubSonic) I almost always end up having to use a CodingHorror.
However, you should be able to do this by using a separate query. Something like: