麻烦或SharePoint CAML [英] Trouble with OR in Sharepoint CAML

查看:258
本文介绍了麻烦或SharePoint CAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询列表,并获得通讯文章后面积极配合简报的列表。

I'm trying to query a list and get newsletter articles back that match the list of active newsletters.

麻烦来尝试通过CAML拉项目时。如果我做一个或循环有两个载,它的伟大工程。例如:

The trouble comes in when trying to pull items via CAML. If I do an OR loop with two CONTAINS, it works great. For example:

<Where>
  <Or>
    <Contains>
      <FieldRef Name=\"Newsletter_x0020_Name\"/>
      <Value Type=\"Lookup\">April 2012</Value>
    </Contains>
    <Contains>
      <FieldRef Name=\"Newsletter_x0020_Name\"/>
      <Value Type=\"Lookup\">May 2012</Value>
    </Contains>
  </Or>
</Where>



伟大工程!

Works great!

添加了第三行,我们有麻烦了:

Add in a third line and we have trouble:

<Where>
  <Or>
    <Contains>
      <FieldRef Name=\"Newsletter_x0020_Name\"/>
      <Value Type=\"Lookup\">April 2012</Value>
    </Contains>
    <Contains>
      <FieldRef Name=\"Newsletter_x0020_Name\"/>
      <Value Type=\"Lookup\">May 2012</Value>
    </Contains>
    <Contains>
      <FieldRef Name=\"Newsletter_x0020_Name\"/>
      <Value Type=\"Lookup\">June 2012</Value>
    </Contains>
  </Or>
</Where>



我确信它是不是这个名字列中的参数(意思是我已经试过每一个可能的组合四月,五月和六月两个两个参数和三个参数实现)并没有什么变化。我可以使用任何一组参数,两列总是工作,和三个总是失败。

I've made sure it wasn't the parameters inside the name column (Meaning I've tried every combination possible of April, May and June in both the two Parameter and three Parameter implementations) and nothing changes. I can use any set of parameters, and two columns always works, and three always fails.

帮助?

推荐答案

我这学到了艰辛的道路,以及 - CAML集团<和> < ;或GT; 只能成对 <工作/ strong>,以表达布尔逻辑。

I learned this the hard way as well - CAML groupings <And> and <Or> only work in pairs to express Boolean logic.

巧妙位(或讨厌,这取决于你如何看待它)是该集团也作为条件本身。因此,在这种情况下,它应该是这样的:

The clever bit (or annoying, depending on how you look at it) is that the groupings also work as conditions themselves. So in this case, it would look like this:

<Or>
    <Or>
        <Condition1/>
        <Condition2/>
    </Or>
    <Condition3/>
</Or>

在上面的例子中,我们都在说要么这个表达式为true,或者Condition3是真的;第一个表达式恰好也有一个评估和冒泡代表一个布尔值的子表达式。

In the case above, we are saying "Either this expression is true, or Condition3 is true"; the first expression happens to also have a sub-expression that is evaluated and bubbled up to represent a single boolean value.

如果你最终写了很多复杂的查询您的应用程序,因为我有,我强烈建议掩藏它的API或类似LINQ一个不错的对象模型的背后,因为XML很烦琐手工编写,而且容易陷入困境。

If you end up writing a lot of complex queries in your applications as I have, I strongly recommend hiding it behind an API or a nice object model like LINQ, because the XML is very cumbersome to write by hand, and easy to mess up.

这篇关于麻烦或SharePoint CAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆