0

我正在开发 Silverlight Web 部件。我有一个列表条目日志。在此列表中,我存储了所有基本信息条目。所有条目均已成功保存。现在我想检索在条目日志列表中创建这些条目的最大日期和最小日期。所以我使用下面的代码

    public void PopulateTimeLog(String paymentStatus, String currentUser, timeLogDelegate populateCombo)
    {
        timeLogDelegateClient = populateCombo;

        ClientContext clientContext = ClientContext.Current;
        List list = clientContext.Web.Lists.GetByTitle("Time Log");

        string query = "<View>";
        query += "<Query>";
        query += "<Where>";
        query += "<And>";
        query += "<Eq>";
        query += "<FieldRef Name='Author'></FieldRef>";
        query += "<Value Type='Lookup'>" + currentUser + "</Value>";
        query += "</Eq>";
        query += "<Eq>";
        query += "<FieldRef Name='Payment_x0020_Status'></FieldRef>";
        query += "<Value Type='Text'>" + paymentStatus + "</Value>";
        query += "</Eq>";
        query += "</And>";
        query += "</Where>";
        query += "<OrderBy>";
        query += "<FieldRef Name='Created' Ascending='False'></FieldRef>";
        query += "</OrderBy>";                       
        query += "</Query>";
        query += "</View>";            

        CamlQuery Query = new CamlQuery();
        Query.ViewXml = query;

        listItemsTimeLog = list.GetItems(Query);
        //clientContext.Load(list);
        //clientContext.Load(listItemsTimeLog);

        clientContext.Load(listItemsTimeLog, itms => itms.Include(
                                                        itm => itm["Created"]));


        clientContext.ExecuteQueryAsync(HandleTimeLogRequestSucceeded, HandleTimeLogRequestFailed);

    }

    private void HandleTimeLogRequestSucceeded(object sender, ClientRequestSucceededEventArgs e)
    {
        ////call back on the UI thread
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
        {

            timeLogDelegateClient(listItemsTimeLog);
        });
    }

在上面的代码中,我将在索引 0 处获取 listItemsTimeLog 中的最大日期,在最后一个索引处获取 listItemsTimeLog 中的最小日期。在上面的查询中,我不想检索 listItemsTimeLog 中的所有日期。如何简化上述查询,以便只获得两个字符串值 - 一个字符串将包含最大日期,另一个字符串将包含最小日期。如果我可以通过网络服务做到这一点,那么对我来说也可以吗?我怎样才能做到这一点 ?您能否提供任何代码以便我可以解决上述问题?

4

1 回答 1

0

您可以为此使用RowLimit,例如

最大限度

<View>
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name='Author'></FieldRef>
          <Value Type='Lookup'>[your use name]</Value>
        </Eq>
        <Eq>
          <FieldRef Name='Payment_x0020_Status'></FieldRef>
          <Value Type='Text'>[ your payment status]</Value>
        </Eq>
      </And>
    </Where>
    <OrderBy>
      <FieldRef Name='Created' Ascending='False'></FieldRef>
    </OrderBy>
  </Query>
 <RowLimit>1</RowLimit>
</View>

<View>
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name='Author'></FieldRef>
          <Value Type='Lookup'>[your use name]</Value>
        </Eq>
        <Eq>
          <FieldRef Name='Payment_x0020_Status'></FieldRef>
          <Value Type='Text'>[ your payment status]</Value>
        </Eq>
      </And>
    </Where>
    <OrderBy>
      <FieldRef Name='Created' Ascending='True'></FieldRef>
    </OrderBy>
  </Query>
 <RowLimit>1</RowLimit>
</View>
于 2011-12-13T14:57:39.933 回答