2011-07-26 85 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");