亚音速 - 带可选参数的查询
使用 C# 3.5 到 VS 2008 和亚音速 2.2。 任何人都知道是否可以创建一个中间有一个“IF”的亚音速查询,具体取决于传递的参数是否大于零。
例如,一个具有两个传递参数的删除方法 - A 和 B。
我想要类似(伪代码)的东西
DELETE from Products
Where productId = A
if(B > 0)
{
AND ProductAttributeId = B
}
,显然它不需要其中的实际“IF”子句,但这就是我想要做的事情的本质与亚音速。我知道我可以根据参数是否存在有两个不同的查询,但我想知道是否有更干净的方法来执行此操作。
谢谢。
Using C# 3.5 through VS 2008 and subsonic 2.2.
Anyone know if it's possible to create a subsonic query that essentially has an 'IF' in the middle of it, depending on whether a passed parameter was, for example, greater than zero.
For example, a delete method that has two passed parameters - A and B.
I want something like (pseudo code)
DELETE from Products
Where productId = A
if(B > 0)
{
AND ProductAttributeId = B
}
Obviously it wouldn't need the actual 'IF' clause in there but that's the essence of what I'm trying to do with subsonic. I know I can just have two different queries depending on whether the parameter is there or not but I was wondering if there's a cleaner way of doing it.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常就是这样做的 - 这不是两个查询,而是一个带有可选添加约束的
SqlQuery
:可能存在拼写错误,我现在无法测试这一点。
That's how I usually do it - it's not two queries, but one
SqlQuery
with optionally added constraints:There may be a typo, I can't test this right now.