Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

RuleUniqueValueAttribute Class

Defines a validation rule that demands the target property’s value be unique.

Namespace: DevExpress.Persistent.Validation

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

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleUniqueValueAttribute :
    RuleBaseAttribute,
    IRuleUniqueValueProperties,
    IRuleSearchObjectProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties,
    IRulePropertyValueProperties

Remarks

Apply this attribute to a business class property to define a validation rule that will check whether this property’s value is unique. Use the CriteriaEvaluationBehavior parameter, to specify whether to look for objects that are currently retrieved from the database, in addition to objects in the database itself. In addition, use the common parameters that are inherited from the RuleBaseAttribute class.

//...
private Priority priority;
[RuleUniqueValue("",DefaultContexts.Save,
   CriteriaEvaluationBehavior=CriteriaEvaluationBehavior.BeforeTransaction)]
public Priority Priority {
   get {
      return priority;
   }
   set {
      SetPropertyValue("Priority ", ref priority , value);
   }
}
//...

The rule generated by the RuleUniqueValueAttribute 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. This is helpful when you need to add a rule to a property which is implemented in a base class provided by a third party library. For details, refer to the Implement Property Value Validation in the Application Model topic.

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

Note

You can apply RuleUniqueValue, RuleObjectExists, RuleIsReferenced, and RuleCombinationOfPropertiesIsUnique rules to persistent business objects only because they search for objects within the application database. If the rule is applied to a base class that has descendants, the condition is tested against objects of all derived types.

Inheritance

Object
Attribute
RuleBaseAttribute
RuleUniqueValueAttribute
See Also