Skip to main content

Limitations of CriteriaOperator.Parse

  • 2 minutes to read

The common way to query objects is to use the static CriteriaOperator.Parse method. However, there are two limitations you must know when using this method:

  • The Parse method does not accept arrays as arguments. Instead, you should use InOperator.

    DateTime[] dates = new DateTime[] { new DateTime(2010, 10, 10), DateTime.Today };
    // Wrong. An exception is raised.
    XPCollection<Order> col1 = new XPCollection<Order>(session1,
        CriteriaOperator.Parse("[OrderDate] in (?)", dates));
    // Right
    XPCollection<Order> col2 = new XPCollection<Order>(session1,
        new InOperator("OrderDate", dates));
  • The Parse method does not work with a string returned by the CriteriaOperator.ToString method, if criteria contain object references.

    // Gets any order
    Order o = session1.FindObject<Order>(null); 
    CriteriaOperator filter = new BinaryOperator("Customer", o.Customer);
    string filterString = filter.ToString();
    // Wrong
    XPCollection<Order> col1 = new XPCollection<Order>(session1,
    // Right
    XPCollection<Order> col2 = new XPCollection<Order>(session1,

To avoid the problems mentioned above, we suggest that you use Simplified Criteria Syntax:

XPCollection<Order> col3 = new XPCollection<Order>(session1, Order.Fields.Customer == o.Customer);


You can register custom enumerations using static methods of the EnumProcessingHelper class and then refer to enumeration values as follows:

Status = ##Enum#MyNamespace.Status,InProgress#

See Also