具有多个字段的嵌套 AND 和 OR 的 CAML 查询
我正在研究概念验证代码,以根据提供给我正在编写的高度特定的搜索 Web 服务的关键字动态生成 CAML。我没有使用 SharePoint 提供的搜索 Web 服务来进行此证明。为了我想要实现的目标,我已经这样做了。从我所有的研究中,我找不到一个接近的例子来说明我想要实现的目标,即检查多个字段的多个值。是的,我已经看过了我的答案,包括这个:需要构建方面的帮助CAML 查询。
话虽如此,如果可能的话,下面的类似 SQL 的查询如何用 CAML 编写呢?
SELECT FirstName, LastName, Description, Profile
FROM SomeFakeTable
WHERE (FirstName = 'John' OR LastName = 'John' OR Description = 'John' OR Profile='John')
AND (FirstName = 'Doe' OR LastName = 'Doe' OR Description = 'Doe' OR Profile='Doe')
AND (FirstName = '123' OR LastName = '123' OR Description = '123' OR Profile='123')
I am working on proof-of-concept code to dynamically generate CAML based on keywords provided to a highly-specific search web service that I am writing. I am not using the SharePoint-provided search web service for this proof. I have done so already for what I am trying to achieve. From all of my research, I cannot find a close example for what I am trying to achieve, which is to check multiple fields for multiple values. Yes, I have looked on SO already for my answer, including this one: Need help on building CAML Query.
With that said, if it is possible, how can the following SQL-like query be written in CAML?
SELECT FirstName, LastName, Description, Profile
FROM SomeFakeTable
WHERE (FirstName = 'John' OR LastName = 'John' OR Description = 'John' OR Profile='John')
AND (FirstName = 'Doe' OR LastName = 'Doe' OR Description = 'Doe' OR Profile='Doe')
AND (FirstName = '123' OR LastName = '123' OR Description = '123' OR Profile='123')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于不允许在一个条件组中放置两个以上的条件(And | Or),因此您必须创建一个额外的嵌套组(MSDN)。表达式
A AND B AND C
如下所示:您的类似 SQL 的示例已转换为 CAML(希望具有匹配的 XML 标记;)):
Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression
A AND B AND C
looks like this:Your SQL like sample translated to CAML (hopefully with matching XML tags ;) ):
您可以尝试 U2U 查询生成器 http://www.u2u.net/res/Tools/CamlQueryBuilder .aspx 您可以使用他们的 API U2U.SharePoint.CAML.Server.dll 和 U2U.SharePoint.CAML.Client.dll
我没有使用它们,但我确信它将帮助您完成任务。
You can try U2U Query Builder http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx you can use their API U2U.SharePoint.CAML.Server.dll and U2U.SharePoint.CAML.Client.dll
I didn't use them but I'm sure it will help you achieving your task.
此代码将使用嵌套子句动态为您生成表达式。我有一个场景,“OR”的数量未知,所以我使用下面的。用法:
这是代码:
This code will dynamically generate the expression for you with the nested clauses. I have a scenario where the number of "OR" s was unknown, so I'm using the below. Usage:
And here's the code: