I need to use the Mircosoft CRM SDK to pull a group of addresses based on the parentid stored in each of the address entities. This parentid naturally corresponds to the GUID of the parent record.
I've built this query two ways: first I simply place the GUID in the condition.Values property, and second I tried using and EntityReference.
If I simply use the GUID the query completes but I receive no results. If I use the EntityReference I get the following exception:
There was an error while trying to serialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:query. The InnerException message was 'Type 'Microsoft.Xrm.Sdk.EntityReference' with data contract name 'EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types
I've also tried building the query using two different methods, however I get the same results along the same lines of GUID input into the condition value.
If I open the Microsoft Dynamics web page for the account I'm working on, I can clearly see that the address has been entered.

How do you go about including GUID to query on the parentid?
Method One
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "parentid";
condition.Operator = ConditionOperator.Equal;
//This works but returns no results
condition.Values.Add(new EntityReference("account", id));
//This throws the above exception
//condition.Values.Add(new EntityReference("account", id));
ColumnSet column = new ColumnSet(true);
QueryExpression query = new QueryExpression();
query.ColumnSet = column;
query.EntityName = "customeraddress";
query.Criteria.AddCondition(condition);
Method Two
QueryExpression queryEx = new QueryExpression
{
EntityName = "customeraddress",
ColumnSet = new ColumnSet(true),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "parentid",
Operator = ConditionOperator.Equal,
//Works but returns no results
Values = {id}
//Throws exception
//Values = {new EntityReference("account", id)}
}
}
}
};


QueryByAttribute? - p e pEntityReference- NealR