"cannot be assigned to -- it is read only" error on ConditionExpression

Jungleman picture Jungleman · Mar 24, 2014 · Viewed 7.2k times · Source

I have to create "between date" condition.

When I write like this:

ConditionExpression modifiedOnCondition = new ConditionExpression();
modifiedOnCondition.AttributeName = "modifiedon";
modifiedOnCondition.Operator = ConditionOperator.Between;
modifiedOnCondition.Values = new Object[] { startDate, endDate };

startDate and endDate are DateTime. I got an error on modifiedOnCondition.Values. It says:

Property or indexer 'Microsoft.Xrm.Sdk.Query.ConditionExpression.Values' cannot be assigned to -- it is read only

How can I fix it?

Answer

Adriano Repetti picture Adriano Repetti · Mar 24, 2014

You can't change Values property after object has been created, just pass it as parameter in ConditionExpression constructor:

var modifiedOnCondition = new ConditionExpression(
    "modifiedon",
    ConditionOperator.Between,
    new Object[] { startDate, endDate });