A newer version of this page is available. Switch to the current version.

RuleCriteriaAttribute Class

Defines a validation rule that demands an object of the target type satisfy a specified criterion.

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v18.2.dll


[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Interface, AllowMultiple = true)]
public class RuleCriteriaAttribute :
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Property Or AttributeTargets.Interface, AllowMultiple:=True)>
Public Class RuleCriteriaAttribute
    Inherits RuleBaseAttribute
    Implements IRuleCriteriaProperties,


Apply this attribute to a business class to define a criterion that must be satisfied by this class' objects. Use the criteria parameter to specify the required criterion. To learn how to write criteria correctly, refer to the Ways to Build Criteria topic. In criteria, you can use Function Criteria Operators. For instance, the "Today = LocalDateTimeToday()" criterion means that the Today property must be set to the current date.

When applying this attribute, use common parameters that are inherited from the RuleBaseAttribute class, in addition to the criteria parameter.

Note that when you need to check whether a property is specified, use the RuleRequiredFieldAttribute, rather than the RuleCriteriaAttribute. However, there are scenarios when you need to use the RuleCriteriaAttribute for this purpose. The following code demonstrates one of them. The Address objects are related to the User and Client objects by the One-To-One relationship. But, the Address object must not have the House property set to 0 when it is assigned to the Client objects.

public class Address : BaseObject {
   public Address(Session session) : base(session) { }
   private string street;
   public string Street {
      get { return street; }
      set { SetPropertyValue("Street", ref street, value); }
   private int house;
   public int House{
      get { return house; }
      set { SetPropertyValue("House", ref house, value); }
[RuleCriteria("", DefaultContexts.Save, "ClientAddress.House != 0",
   "House should not be 0", SkipNullOrEmptyValues = false)]
public class Client : BaseObject {
   public Client(Session session) : base(session) { }
   public string ClientName{};
   public Address ClientAddress{};
public class User : BaseObject {
   public User(Session session) : base(session) { }
   public string UserName{};
   public Address UserAddress{};

In the code above, the RuleCriteriaAttribute has the RuleBaseAttribute.SkipNullOrEmptyValues parameter set to false. This is required, so that the rule defined by this attribute is checked when the target property is not specified.

The rule generated by the RuleCriteriaAttribute will be loaded to the Application Model's IModelValidationRules node. So, you can customize this rule via the Model Editor. In addition, you can create new rules in the Model Editor as well. For details, refer to the Implement Property Value Validation in the Application Model topic.

You can see examples of using the RuleCriteria and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\FeatureCenter folder, by default.


See Also