C# Dynamics CRM FilterExpression EntityReference

c#, dynamics-crm, entity, filter, reference

Solution

`Guid` should be fine - are you sure that your Guid value is correct?

Problem

I am trying to build a FilterExpression with a Lookup value. I have tried passing an EntityReference and a Guid. The EntityReference resulted in a runtime error, whereas the Guid resulted in nothing being returned (the EntityCollection is empty, although I know for sure that at least one entity should be returned). What am I doing wrong? ``` FilterExpression filter = new FilterExpression(LogicalOperator.And); filter.AddCondition(new ConditionExpression("referenced_entity", ConditionOperator.Equal, referencedEntityGuid)); retrieveRequest.Query = new QueryExpression { Criteria = filter, EntityName = "my_entity", ColumnSet = new ColumnSet(new[] { "referenced_entity", "a_property", "another_property" }) }; ``` I would like to note that `referencedEntityGuid` is an instance of Guid (obviously) and that when I deactivate the filter, the return type of the `referenced_entity`-property is `EntityReference`. Additionally, `TotalRecordCount` equals -1.

Original source