2011-07-26 86 views
2

我試圖通過EntityReference篩選數據,但沒有運氣。如果沒有where子句運行良好與where子句我得到以下錯誤:Dynamics CRM 2011篩選從Web服務返回的數據

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

這裏是我的方法調用CRMService:

/// <summary> 
     /// Gets the categories. 
     /// </summary> 
     /// <returns></returns> 
     public IEnumerable<category> GetCategoriesExcludingSomething() 
     { 
      IEnumerable<category> data = CrmClient.categorySet.OrderBy(x => x.SubCategory).ThenBy(x => x.itf_name); 

      return data.Where(x => x.SubCategory.ToString() == "SomethingToExclude"); 
     } 

我一直在使用SubCategory.Name也嘗試過,但它給出相同的錯誤。我認爲這與它使用早期綁定的事實有關,但是在調試時我無法獲得任何有用的信息。

任何建議或幫助將是巨大的,這應該是很容易:/

回答

2

根據此文件:http://technet.microsoft.com/en-us/library/gg328328.aspx

The LINQ query provider supports a subset of the LINQ operators. Not all conditions that can be expressed in LINQ are supported.

orderBy supports ordering by entity attributes, such as Contact.FullName.

你可以做的是首先使用where子句,然後用ToList()方法。在此之後,您將獲得一組數據,您可以在其中使用所有常見的Linq查詢。

另外,試圖OrderBy一個EntityReference並不是一個好辦法。你應該嘗試訂購這樣的:

OrderBy(x => x.SubCategory.Id) 

where: The left side of the clause must be an attribute name and the right side of the clause must be a value. You cannot set the left side to a constant. Both the sides of the clause cannot be constants. Supports the String functions Contains, StartsWith, EndsWith, and Equals

你可以做這裏是由id或者名稱或者過濾值(也就是你將不得不從的EntityReference唯一的相關信息在這種情況下) 。

Where(x => x.SubCategory.Name == "CategoryNameToExclude");