Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Includ OptionSetValue in QueryExpression

I need to query an OptionSetValue field to find active records according to a query done based on a specific Id. However, each time the query below executes I get the following error:

the type with data contract name optionsetvalue is not expected

How do I include an OptionSetValue in the Values attribute of a QueryExpression Condition?

queryEx = new QueryExpression
{
    EntityName = "account",
    ColumnSet = new ColumnSet(true),
    Criteria =
    {
        FilterOperator = LogicalOperator.And,
        Conditions =
        {
            new ConditionExpression
            {
                AttributeName = "neu_id",
                Operator = ConditionOperator.Equal,
                Values = {agency.ReferenceNumber}
            },
            new ConditionExpression
            {
                AttributeName = "neu_appointmentstatus",
                Operator = ConditionOperator.Equal,
                Values = {new OptionSetValue(279660000)}
            }
        }
    }
};

EntityCollection collection = _client.RetrieveMultiple(queryEx);
like image 403
NealR Avatar asked Dec 26 '22 00:12

NealR


1 Answers

In your condition you need to set the integer value of the optionset. So the code will be:

new ConditionExpression
    {
        AttributeName = "neu_appointmentstatus",
        Operator = ConditionOperator.Equal,
        Values = 279660000
    }
like image 96
Guido Preite Avatar answered Dec 31 '22 14:12

Guido Preite