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
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:
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).