开发者

Dynamics CRM 2011 filtering data returned from web service

I am trying to filter data by the EntityReference with no luck. Without the where clause it runs fine with the where clause I get the following error:

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.

Here is my method that calls the 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");
        }

I have tried using SubCategory.Name also but it开发者_如何转开发 gives the same error. I think it's related to the fact it uses early binding or something along those lines but I couldn't get any useful information when debugging.

Any advice or help would be great, this should be easy :/


According to this documentation: 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.

What you could do is to use the where clause first, and then use the ToList() method. After this, you'll have a collection of data on which you can use all the common Linq queries.

Also, trying to OrderBy an EntityReference is not the good way to do it. You should try ordering like this:

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

What you could do here is either filtering values by the Id or by the Name (that's the only relevant informations you'll have from the EntityReference in this case).

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜