“cannot be assigned to — it is read only” error on ConditionExpression

寵の児 提交于 2019-12-10 20:34:43

问题


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?


回答1:


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 });


来源:https://stackoverflow.com/questions/22605180/cannot-be-assigned-to-it-is-read-only-error-on-conditionexpression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!