亚音速查询:生成的查询存在问题

发布于 2024-08-11 00:18:36 字数 464 浏览 5 评论 0原文

我在亚音速查询方面遇到问题。问题是,我有一个视图,我想查询它的数据以生成类似以下 SQL 语句的内容:

select * 
from myView
where (col1 like '%a%' or col2 like '%a%' or col3 like '%a%') 
  and col4 = 1 and col5 = 2

但是提交到数据库的查询是这样的:

select * 
from myView
where col1 like '%a%' or col2 like '%a%' or col3 like '%a%' 
  and col4 = 1 and col5 = 2

有没有办法执行类似于第一个查询的操作?

请注意,我正在使用 .net 2.0 和 subsonic 2.2

提前谢谢您。

即便如此,亚音速规则!

I'm having a problem with subsonic query. The deal is, I have a view and I want to query it's data to produce something like the following SQL statement:

select * 
from myView
where (col1 like '%a%' or col2 like '%a%' or col3 like '%a%') 
  and col4 = 1 and col5 = 2

But instead the query that is submited to the DB is something like this:

select * 
from myView
where col1 like '%a%' or col2 like '%a%' or col3 like '%a%' 
  and col4 = 1 and col5 = 2

Is there a way to do something like the fisrt query?

Please note I'm using .net 2.0 and subsonic 2.2

Thank you in advance.

Even do, Subsonic rules!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那一片橙海, 2024-08-18 00:18:36

您需要使用约束表达式< /a>:WhereExpressionAndExpressionOrExpressionEndExpression

“WhereExpression”(或 Or/AndExpression)后面的任何内容都将包含在括号中。您可以使用“CloseExpression()”关闭表达式,或者如果启动另一个表达式(如上面的 OrExpression)或查询结束,它将为您关闭。

另请参阅:使用嵌套Where/And/Or

You need to use the Constraint Expressions: WhereExpression, AndExpression, OrExpression, EndExpression.

Anything following “WhereExpression” (or Or/AndExpression) will be wrapped in parentheses. You can close the expression by using “CloseExpression()”, or it will be closed for you if another is started (as with OrExpression above) or if the query ends.

Also see: Using Nested Where/And/Or.

鹿! 2024-08-18 00:18:36

如果您发布当前的代码,也许我能够给出更具体的答案,但基本上您必须启动 WhereExpression
例如这样的代码:

var usersQuery = new Select(new SubSonic.TableSchema.TableColumn[] { User.UserIdColumn, User.NameColumn })
            .From(User.Schema)            
            .WhereExpression(User.UserIdColumn.ColumnName).IsEqualTo(1).Or(User.UserIdColumn).IsEqualTo(2)
            .CloseExpression()
            .And(User.NameColumn).Like("a")

给出如下查询:

SELECT [dbo].[Users].[UserId], [dbo].[Users].[Name]
 FROM [dbo].[Users]
 WHERE ([dbo].[Users].[UserId] = @UserId0 OR [dbo].[Users].[UserId] = @UserId)
 AND [dbo].[Users].[Name] LIKE @Name

If you post your current code maybe I will be able to give more specific answer but basically you have to start WhereExpression.
For example code like this:

var usersQuery = new Select(new SubSonic.TableSchema.TableColumn[] { User.UserIdColumn, User.NameColumn })
            .From(User.Schema)            
            .WhereExpression(User.UserIdColumn.ColumnName).IsEqualTo(1).Or(User.UserIdColumn).IsEqualTo(2)
            .CloseExpression()
            .And(User.NameColumn).Like("a")

Gives query like:

SELECT [dbo].[Users].[UserId], [dbo].[Users].[Name]
 FROM [dbo].[Users]
 WHERE ([dbo].[Users].[UserId] = @UserId0 OR [dbo].[Users].[UserId] = @UserId)
 AND [dbo].[Users].[Name] LIKE @Name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文