2011-06-15 65 views
3

我正在閱讀使用Odata RESTful服務的Sharepoint列表數據(> 20000個條目),詳情請參閱此處的-http://blogs.msdn.com/b/ericwhite/archive/2010/12/09/ odata-rest-api-to-query-a-sharepoint-list.aspxOData服務未返回完整回覆

我能夠讀取數據,但我只能得到前1000條記錄。我還檢查了Sharepoint服務器上的List View Throttling設置爲5000。好心提醒。

更新:

@Turker:你的答案是當場上!非常感謝你。我能夠在第一次迭代中獲得第一批2000條記錄。但是,我在while循環的每次迭代中都得到相同的記錄。我的代碼如下 -

      ...initial code... 
        int skipCount =0; 
    while (((QueryOperationResponse)query).GetContinuation() != null) 
       { 
        //query for the next partial set of customers 
        query = dc.Execute<CATrackingItem>(
         ((QueryOperationResponse)query).GetContinuation().NextLinkUri 
         ); 

        //Add the next set of customers to the full list 
        caList.AddRange(query.ToList()); 

        var results = from d in caList.Skip(skipCount) 
            select new 
            { 
             Actionable = Actionable, 
            }; Created = d.Created, 

         foreach (var res in results) 
         { 

          structListColumns.Actionable = res.Actionable; 
          structListColumns.Created= res.Created; 
         } 
         skipCount = caList.Count; 
        }//Close of while loop 

回答

6

您是否在Feed的末尾看到<link rel="next">元素?

例如,如果你看一下

http://services.odata.org/Northwind/Northwind.svc/Customers/

你會看到

<link rel="next" href="http://services.odata.org/Northwind/Northwind.svc/Customers/?$skiptoken='ERNSH'" /> 

的,這意味着該服務是實現服務器端分頁的進料結束,你需要發送

http://services.odata.org/Northwind/Northwind.svc/Customers/?$skiptoken='ERNSH' 

查詢得到下一組r esults。

0

我沒有看到你的代碼有什麼特別的錯誤。您可以嘗試轉儲所請求的URL(從代碼或使用類似fiddler的東西)來查看客戶端是否確實發送了相同的查詢(從而獲得相同的響應)。

在任何情況下,這裏是一個示例代碼不工作(使用示例服務):

DataServiceContext ctx = new DataServiceContext(new Uri("http://services.odata.org/Northwind/Northwind.svc")); 

QueryOperationResponse<Customer> response = (QueryOperationResponse<Customer>)ctx.CreateQuery<Customer>("Customers").Execute(); 
do 
{ 
    foreach (Customer c in response) 
    { 
     Console.WriteLine(c.CustomerID); 
    } 

    DataServiceQueryContinuation<Customer> continuation = response.GetContinuation(); 
    if (continuation != null) 
    { 
     response = ctx.Execute(continuation); 
    } 
    else 
    { 
     response = null; 
    } 
} while (response != null); 
0

我有同樣的問題,並希望它是一個通用的解決方案。 所以我用一個GetAlltems方法擴展了DataServiceContext。

public static List<T> GetAlltems<T>(this DataServiceContext context) 
    { 
     return context.GetAlltems<T>(null); 
    } 

    public static List<T> GetAlltems<T>(this DataServiceContext context, IQueryable<T> queryable) 
    { 
     List<T> allItems = new List<T>(); 
     DataServiceQueryContinuation<T> token = null; 

     EntitySetAttribute attr = (EntitySetAttribute)typeof(T).GetCustomAttributes(typeof(EntitySetAttribute), false).First(); 

     // Execute the query for all customers and get the response object. 
     DataServiceQuery<T> query = null; 

     if (queryable == null) 
     { 
      query = context.CreateQuery<T>(attr.EntitySet); 
     } 
     else 
     { 
      query = (DataServiceQuery<T>) queryable; 
     } 

     QueryOperationResponse<T> response = query.Execute() as QueryOperationResponse<T>; 

     // With a paged response from the service, use a do...while loop 
     // to enumerate the results before getting the next link. 
     do 
     { 
      // If nextLink is not null, then there is a new page to load. 
      if (token != null) 
      { 
       // Load the new page from the next link URI. 
       response = context.Execute<T>(token); 
      } 

      allItems.AddRange(response); 
     } 
     // Get the next link, and continue while there is a next link. 
     while ((token = response.GetContinuation()) != null); 

     return allItems; 
    }