Rohit Gupta

Engaging talk on Microsoft Technologies ....My Resume

  Home  |   Contact  |   Syndication    |   Login
  41 Posts | 0 Stories | 52 Comments | 0 Trackbacks

News



Twitter












Archives

Image Galleries

Personal

Monday, November 08, 2010 #

If you generate CAML using LINQ to SharePoint in Visual Studio 2010 then you might see this bug popup:

If you are writing a CAML query to filter records based on Date and Time, and this query is generated using LINQ To SharePoint then you will get the following CAML query generated:

<View>
  <Query>
    <Where>
        <And>
          <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>{0}</Value>
          </Eq>
          <Lt>
            <FieldRef Name='QuoteTime' IncludeTimeValue='TRUE' />
            <Value Type='DateTime>{1}</Value>
          </Lt>
        </And>
     </Where>
  </Query>
  <RowLimit Paged='TRUE'>100</RowLimit>
</View>

However the above is incorrect since the IncludeTimeValue Attribute is on the wrong element. The correct CAML query is as follows:

<View>
  <Query>
    <Where>
        <And>
          <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>{0}</Value>
          </Eq>
          <Lt>
            <FieldRef Name='QuoteTime' />
            <Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value>
          </Lt>
        </And>
     </Where>
  </Query>
  <RowLimit Paged='TRUE'>100</RowLimit>
</View>

Note that the IncludeTimeValue attribute is on the Value Element and not the FieldRef element. Thus if you need to filter records based on Date & Time then include the “IncludeTimeValue” attribute on the Value Element.