Skip to main content
.NET 8.0+

RuleBaseAttribute.TargetCriteria Property

Specifies a criterion that must be satisfied by the validated object or property to check rules.

Namespace: DevExpress.Persistent.Validation

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

Declaration

public string TargetCriteria { get; set; }

Property Value

Type Description
String

A string that represents a criterion that must be satisfied to check validation rules.

Remarks

When defining a rule for a business class or property, you should specify a context for checking this rule. In some scenarios, you may need to check whether a criterion is satisfied by the object or property before checking the rule. For instance, the RuleRequiredField rule can be checked for the SpouseName property, if the IsMarried property is set to true. The following code sample demonstrates how to define this rule.

public class Contact : BaseObject {
    // ...
    [RuleRequiredField("SpouseNameIsRequiredWhenMarried", DefaultContexts.Save,
       SkipNullOrEmptyValues = false, TargetCriteria = "[IsMarried] == True")]
    public virtual String SpouseName { get; set; }
    public virtual bool IsMarried { get; set; }
    // ...
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

Note

You can use Function Criteria Operators when passing a criteria as the TargetCriteria parameter. For details on how to write a criteria, refer to the Ways to Build Criteria topic.

Implements

See Also