private static MetadataConditionOperator GetNegatedOperator(this MetadataConditionOperator conditionOperator) { switch (conditionOperator) { case MetadataConditionOperator.Equals: return(MetadataConditionOperator.NotEquals); case MetadataConditionOperator.NotEquals: return(MetadataConditionOperator.Equals); case MetadataConditionOperator.LessThan: throw new NotSupportedException("Can not negate a 'Less Than' filter when performing metadata queries, as the Crm Sdk does not allow for 'Greater Than Equals' condition operator."); case MetadataConditionOperator.GreaterThan: throw new NotSupportedException("Can not negate a 'Greater Than' filter when performing metadata queries, as the Crm Sdk does not allow for 'Less Than Equals' condition operator."); case MetadataConditionOperator.In: return(MetadataConditionOperator.NotIn); case MetadataConditionOperator.NotIn: return(MetadataConditionOperator.In); default: throw new NotSupportedException("Can not negate condition operator: " + conditionOperator); } }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.Xrm.Sdk.Metadata.Query.MetadataConditionExpression"></see> class.</summary> /// <param name="conditionOperator">Type: <see cref="T:Microsoft.Xrm.Sdk.Metadata.Query.MetadataConditionOperator"></see>. The condition operator.</param> /// <param name="propertyName">Type: Returns_String. The name of the metadata property in the condition expression.</param> /// <param name="value">Type: Returns_Object The value for the metadata property.</param> public MetadataConditionExpression( string propertyName, MetadataConditionOperator conditionOperator, object value) { this.PropertyName = propertyName; this.ConditionOperator = conditionOperator; this.Value = value; }
private void SetConditionExpressionValue(MetadataConditionExpression condition, MetadataConditionOperator conditionOperator, params object[] values) { condition.ConditionOperator = conditionOperator; if (values != null) { // is the literal a foreach (var value in values) { if (value is Array) { var vals = new List <object>(); foreach (var o in value as Array) { vals.Add(o); } condition.Value = vals; } else { if (condition.Value != null) { throw new NotSupportedException("You cannot use multiple where condition values in a metadata query. " + condition.Value.ToString()); } condition.Value = value; } } } }