Skip to main content
.NET Framework 4.6.2+

RuleRangeAttribute Class

Defines a validation rule that demands the target property’s value be within the specified value range (including the range’s end points).

Namespace: DevExpress.Persistent.Validation

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

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleRangeAttribute :
    RuleBaseAttribute,
    IRuleRangeProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties,
    IRuleSupportsCollectionAggregatesProperties

Remarks

Apply this attribute to a business class property to define a validation rule that will check whether this property’s value is within the specified range. Use the minimalValue and maximumValue parameters to specify the start and end points of the target property value’s range. These parameter values must be the same type as the property or a value type that implements the IComparable interface; otherwise, an ArgumentException is thrown.

You can use Function Criteria Operators as the minimalValue and maximumValue parameter values. For instance, you can pass the LocalDateTimeLastWeek() and LocalDateTimeToday parameters to check whether the target property’s value is set to a date from last week.

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

using System;
using DevExpress.Persistent.Validation;
//...
[RuleRange("LastSevenDays_RuleRange", "Save", "AddDays(LocalDateTimeToday(), -7)", 
    "LocalDateTimeToday()", ParametersMode.Expression)]
public virtual DateTime LastSevenDays { get; set; }
//...
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

The rule generated by the RuleRangeAttribute will be loaded to the Application Model‘s IModelValidationRules node. You can customize this rule with the Model Editor. You can also create new rules in the Model Editor. This is helpful when you need to add a rule to a property that is implemented in a base class supplied by a third party library. Refer to the following topic for details: Implement Property Value Validation.

You can see examples of how to use the RuleRange and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 24.2\Components\XAF\FeatureCenter.NETFramework.XPO folder.

Inheritance

See Also