zoukankan      html  css  js  c++  java
  • 学习:New in SharePoint 2010 CAML Query <IN>,<INCLUDES> &< NOT INCLUDES>(转)

    Even though Microsoft encourages using LINQ in SharePoint 2010, they introduced some new CAML Query schema elements. They are

    · IN

    · INCLUDES

    · NOT INCLUDES

    IN:

    This is something work as same as what we see in SQL Query. We can provide a collection of Items to filter. Previously in SharePoint 2007 we have to use OR operator to do this.. But using OR for multiple times for multiple values will lead to lack in code clarity. So IN operator is considering as good.

    Here I have following SharePoint List.

    In the above list if want to select the items having designation like Engineer and Architect I have to write like this in SharePoint 2007.

    01 <Where>
    02   
    03 <Or>
    04   
    05 <Eq>
    06   
    07 <FieldRef Name='Designation' />
    08   
    09 <Value Type='Text'>Engineer</Value>
    10   
    11 </Eq>
    12   
    13 <Eq>
    14   
    15 <FieldRef Name='Designation' />
    16   
    17 <Value Type='Text'>Architect</Value>
    18   
    19 </Eq>
    20   
    21 </Or>
    22   
    23 </Where>

    The above can be written in SharePoint 2010 as

    01 <Where>
    02   
    03 <In>
    04   
    05 <FieldRef Name='Designation' />
    06   
    07 <Values>
    08   
    09 <Value Type='Text'>Engineer</Value>
    10   
    11 <Value Type='Text'>Architect</Value>
    12   
    13 </Values>
    14   
    15 </In>
    16   
    17 </Where>
    Both will yield the same output as shown below.

    INCLUDES:

    MSDN Def: If the specified field is a Lookup field that allows multiple values, specifies that the Value element is included in the list item for the field that is specified by the FieldRef element.

    If you did not understand the above definition from MSDN, check the following example.

    Here is a sample Employee list.

    Here Specialization is a MultiSelect Lookup column.

    I need to select People who are specialized in XML first and then specialized .Net also. This can be done using Includes.

    SPQuery needs to framed like this

    01 <Where>
    02   
    03 <And>
    04   
    05 <Eq>
    06   
    07 <FieldRef Name=""Specialization""/>
    08   
    09 <Value Type=""Lookup"">XML</Value>
    10   
    11 </Eq>
    12   
    13 <Includes>
    14   
    15 <FieldRef Name='Specialization'/>
    16   
    17 <Value Type='Lookup'>.Net</Value>
    18   
    19 </Includes>
    20   
    21 </And>
    22   
    23 </Where>
    Then the specified output will be

    NOTINCLUDES:

    It will do opposite to what Includes will do.

    In the above list I like to have all the people who are specialized in SQL Server but not specialized in Crystal Report.

    Here my SPQuery

    01 <Where>
    02   
    03 <And>
    04   
    05 <Eq>
    06   
    07 <FieldRef Name=""Specialization""/>
    08   
    09 <Value Type=""Lookup"">SQL Server</Value>
    10   
    11 </Eq>
    12   
    13 <NotIncludes>
    14   
    15 <FieldRef Name='Specialization'/>
    16   
    17 <Value Type='Lookup'>Crystal Report</Value>
    18   
    19 </NotIncludes>
    20   
    21 </And>
    22   
    23 </Where>

    Note: As you see in <IN> operation you have <Values> as the child. Here we can specify multiple items. In the MSDN they specify it is apply to <Includes> and <NotIncludes>. But it is not working. I don’t know. Why?

    Come From: http://rmanimaran.wordpress.com/2011/03/11/new-in-sharepoint-2010-caml-query/

  • 相关阅读:
    【WPF】给下拉列表ComboBox绑定数据
    【C#】POST请求参数含中文,服务器解析得到乱码
    CentOS下搭建SVN服务器
    MySQL之ALTER
    深入PHP内核之ZVAL
    关于zend_parse_parameters函数
    PHP数组
    shell中比较字符串大小,>和<前需要加上进行转义,否则会输出到文件了
    awk编程基础
    【读书笔记】《Python_Cookbook3》第一章:数据结构和算法
  • 原文地址:https://www.cnblogs.com/LeimOO/p/2178455.html
Copyright © 2011-2022 走看看