这个获取异常 "can not complete this action. Please try again" 的 caml 查询有什么问题?

What is wrong with this caml query to get exception "can not complete this action. Please try again"?

我正在 SharePoint 列表上实施 caml 查询! 我有 5 个条件,我将每 2 个条件放在一个标签中。但它仍然得到这个例外:"can not complete this action. please try again!"

<And>
    <Eq>
        <FieldRef Name='fieldName1' />
        <Value Type='Text' >value1</Value>
    </Eq>
    <And>
        <Contains>
            <FieldRef Name='fieldName2' />
            <Value Type='Text' >value2</Value>
        </Contains>
        <Contains>
            <FieldRef Name='fieldName3' />
            <Value Type='Text' >value3</Value>
        </Contains>
    </And>
    <And>
        <Eq>
            <FieldRef Name='fieldName4' />
            <Value Type='DateTime' IncludeTimeValue='false'>2019-06-22</Value>
        </Eq>
        <Eq>
            <FieldRef Name='fieldName5' />
            <Value Type='DateTime' IncludeTimeValue='false'>2019-05-06</Value>
        </Eq>
    </And>
</And>

我的查询有什么问题?

对于涉及多个字段的比较,它更像是自下而上的方法,您开始比较 2 个字段,然后是第 3 个字段的结果,然后是第 4 个字段的结果,依此类推。所以,你的查询应该是这样的:

      <And>
     <Eq>
        <FieldRef Name='fieldName1' />
        <Value Type='Text'>value1</Value>
     </Eq>
     <And>
        <Contains>
           <FieldRef Name='fieldName2' />
           <Value Type='Text'>value2</Value>
        </Contains>
        <And>
           <Contains>
              <FieldRef Name='fieldName3' />
              <Value Type='Note'>value3</Value>
           </Contains>
           <And>
              <Eq>
                 <FieldRef Name='fieldName4' />
                 <Value Type='Text'>value4</Value>
              </Eq>
              <Eq>
                 <FieldRef Name='fieldName5' />
                 <Value Type='Text'>value5</Value>
              </Eq>
           </And>
        </And>
     </And>
  </And>

我明白我的错了,我用递归算法进行查询。如果有人帮助提高它的生产力,我很高兴:

public static void main()
{
    string NestedQuery = "";
    int NestedQueryCounter = 0;
    string query = "<View><Query><Where>";
    var whereClauses = new List<string>();
    whereClauses.Add(SetupQueryExpression("FirstFiled", FirstValue, "Text", "Eq"));
    whereClauses.Add(SetupQueryExpression("SecondFiled",SecondValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ThirdField", ThirdValue, "Text", "Contains"));
    whereClauses.Add(SetupQueryExpression("ForthField", ForthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    whereClauses.Add(SetupQueryExpression("FifthField",FifthValue, "DateTime", "Eq", "IncludeTimeValue='false'"));
    NestedWhereClauses(whereClauses, "<And>", "</And>");
    query += NestedQuery;
    query += "</Where></Query></View>"; 
}

private string SetupQueryExpression(string fieldName, string fieldValue, string dataType, string condition, 
            string extraValueCondition = "")
{
    string query = @"<{0}>
                         <FieldRef Name='{1}' /><Value Type='{2}' {4}>{3}</Value>
                     </{0}>";
    return string.Format(query, condition, fieldName, dataType, fieldValue, extraValueCondition);
}

private void NestedWhereClauses(List<string> whereCalauses, string mainCondition, string endMainCondition)
{
    if (2 == whereCalauses.Count)
    {
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        NestedQuery += whereCalauses[1];
        NestedQuery += endMainCondition;
        for (int counter = 0; counter < NestedQueryCounter; counter++)
            NestedQuery += endMainCondition;
    }
    else
    {
        NestedQueryCounter++;
        NestedQuery += mainCondition;
        NestedQuery += whereCalauses[0];
        whereCalauses.RemoveAt(0);
        NestedWhereClauses(whereCalauses, mainCondition, endMainCondition);
    }
}