Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Collapse]eXpressApp Framework
 [Expand]Fundamentals
 [Expand]Getting Started
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Functional Testing
 [Expand]Deployment
 [Expand]Task-Based Help
 [Expand]Frequently Asked Questions
 [Collapse]API Reference
  [Expand]DevExpress.EasyTest.Framework
  [Expand]DevExpress.ExpressApp
  [Expand]DevExpress.ExpressApp.Actions
  [Expand]DevExpress.ExpressApp.AuditTrail
  [Expand]DevExpress.ExpressApp.Chart
  [Expand]DevExpress.ExpressApp.Chart.Web
  [Expand]DevExpress.ExpressApp.Chart.Win
  [Expand]DevExpress.ExpressApp.CloneObject
  [Expand]DevExpress.ExpressApp.ConditionalAppearance
  [Expand]DevExpress.ExpressApp.Dashboards
  [Expand]DevExpress.ExpressApp.Dashboards.Web
  [Expand]DevExpress.ExpressApp.Dashboards.Win
  [Expand]DevExpress.ExpressApp.Data
  [Expand]DevExpress.ExpressApp.DC
  [Expand]DevExpress.ExpressApp.DC.ClassGeneration
  [Expand]DevExpress.ExpressApp.Editors
  [Expand]DevExpress.ExpressApp.EF
  [Expand]DevExpress.ExpressApp.EF.Utils
  [Expand]DevExpress.ExpressApp.FileAttachments.Web
  [Expand]DevExpress.ExpressApp.FileAttachments.Win
  [Expand]DevExpress.ExpressApp.Filtering
  [Expand]DevExpress.ExpressApp.HtmlPropertyEditor.Web
  [Expand]DevExpress.ExpressApp.HtmlPropertyEditor.Win
  [Expand]DevExpress.ExpressApp.Kpi
  [Expand]DevExpress.ExpressApp.Layout
  [Expand]DevExpress.ExpressApp.Maps.Mobile
  [Expand]DevExpress.ExpressApp.Maps.Mobile.Editors
  [Expand]DevExpress.ExpressApp.Maps.Web
  [Expand]DevExpress.ExpressApp.Maps.Web.Helpers
  [Expand]DevExpress.ExpressApp.MiddleTier
  [Expand]DevExpress.ExpressApp.Mobile
  [Expand]DevExpress.ExpressApp.Mobile.Editors
  [Expand]DevExpress.ExpressApp.Mobile.MobileModel
  [Expand]DevExpress.ExpressApp.Mobile.SystemModule
  [Expand]DevExpress.ExpressApp.Model
  [Expand]DevExpress.ExpressApp.Model.Core
  [Expand]DevExpress.ExpressApp.Model.NodeGenerators
  [Expand]DevExpress.ExpressApp.ModelEditor
  [Expand]DevExpress.ExpressApp.Notifications
  [Expand]DevExpress.ExpressApp.Notifications.Web
  [Expand]DevExpress.ExpressApp.Notifications.Win
  [Expand]DevExpress.ExpressApp.PivotChart
  [Expand]DevExpress.ExpressApp.PivotChart.Web
  [Expand]DevExpress.ExpressApp.PivotChart.Win
  [Expand]DevExpress.ExpressApp.PivotGrid
  [Expand]DevExpress.ExpressApp.PivotGrid.Web
  [Expand]DevExpress.ExpressApp.PivotGrid.Win
  [Expand]DevExpress.ExpressApp.Reports
  [Expand]DevExpress.ExpressApp.Reports.Web
  [Expand]DevExpress.ExpressApp.Reports.Win
  [Expand]DevExpress.ExpressApp.ReportsV2
  [Expand]DevExpress.ExpressApp.ReportsV2.Web
  [Expand]DevExpress.ExpressApp.ReportsV2.Win
  [Expand]DevExpress.ExpressApp.Scheduler
  [Expand]DevExpress.ExpressApp.Scheduler.Web
  [Expand]DevExpress.ExpressApp.Scheduler.Win
  [Expand]DevExpress.ExpressApp.ScriptRecorder
  [Expand]DevExpress.ExpressApp.ScriptRecorder.Web
  [Expand]DevExpress.ExpressApp.ScriptRecorder.Win
  [Expand]DevExpress.ExpressApp.Security
  [Expand]DevExpress.ExpressApp.Security.Adapters
  [Expand]DevExpress.ExpressApp.Security.ClientServer.Wcf
  [Expand]DevExpress.ExpressApp.Security.EF.Adapters
  [Expand]DevExpress.ExpressApp.Security.Strategy
  [Expand]DevExpress.ExpressApp.Security.Xpo.Adapters
  [Expand]DevExpress.ExpressApp.StateMachine
  [Expand]DevExpress.ExpressApp.SystemModule
  [Expand]DevExpress.ExpressApp.Templates
  [Expand]DevExpress.ExpressApp.Templates.ActionContainers
  [Expand]DevExpress.ExpressApp.TreeListEditors
  [Expand]DevExpress.ExpressApp.TreeListEditors.Web
  [Expand]DevExpress.ExpressApp.TreeListEditors.Win
  [Expand]DevExpress.ExpressApp.Updating
  [Expand]DevExpress.ExpressApp.Utils
  [Collapse]DevExpress.ExpressApp.Validation
   [Expand]ActionValidationController Class
   [Expand]ContextValidatingEventArgs Class
   [Expand]CustomGetAggregatedObjectsToValidateEventArgs Class
   [Expand]CustomizeApplicationRuntimeRulesEventArgs Class
   [Expand]CustomizeRulesEventArgs Class
   [Expand]DeleteContextValidatingEventArgs Class
   [Expand]IModelActionValidationContexts Interface
   [Expand]IModelApplicationValidation Interface
   [Expand]IModelLayoutManagerOptionsValidation Interface
   [Expand]IModelRuleBase Interface
   [Expand]IModelValidation Interface
   [Expand]IModelValidationContext Interface
   [Expand]IModelValidationContexts Interface
   [Expand]IModelValidationRules Interface
   [Expand]ModelValidationContextsNodeGenerator Class
   [Expand]ModelValidationRulesNodeGenerator Class
   [Expand]NeedToValidateObjectEventArgs Class
   [Collapse]PersistenceValidationController Class
     PersistenceValidationController Members
     PersistenceValidationController Constructor
    [Expand]PersistenceValidationController Events
   [Expand]RuleSetInitializedEventArgs Class
   [Expand]ValidationModule Class
  [Expand]DevExpress.ExpressApp.Validation.Web
  [Expand]DevExpress.ExpressApp.Validation.Win
  [Expand]DevExpress.ExpressApp.ViewVariantsModule
  [Expand]DevExpress.ExpressApp.Web
  [Expand]DevExpress.ExpressApp.Web.Controls
  [Expand]DevExpress.ExpressApp.Web.Editors
  [Expand]DevExpress.ExpressApp.Web.Editors.ASPx
  [Expand]DevExpress.ExpressApp.Web.SystemModule
  [Expand]DevExpress.ExpressApp.Web.Templates
  [Expand]DevExpress.ExpressApp.Web.Utils
  [Expand]DevExpress.ExpressApp.Win
  [Expand]DevExpress.ExpressApp.Win.Core
  [Expand]DevExpress.ExpressApp.Win.Editors
  [Expand]DevExpress.ExpressApp.Win.Model
  [Expand]DevExpress.ExpressApp.Win.SystemModule
  [Expand]DevExpress.ExpressApp.Win.Templates
  [Expand]DevExpress.ExpressApp.Win.Templates.Navigation
  [Expand]DevExpress.ExpressApp.Workflow
  [Expand]DevExpress.ExpressApp.Workflow.Win
  [Expand]DevExpress.ExpressApp.Xpo
  [Expand]DevExpress.ExpressApp.Xpo.Utils
  [Expand]DevExpress.Persistent.Base
  [Expand]DevExpress.Persistent.Base.General
  [Expand]DevExpress.Persistent.Base.ReportsV2
  [Expand]DevExpress.Persistent.Base.Security
  [Expand]DevExpress.Persistent.BaseImpl
  [Expand]DevExpress.Persistent.BaseImpl.EF
  [Expand]DevExpress.Persistent.BaseImpl.EF.PermissionPolicy
  [Expand]DevExpress.Persistent.BaseImpl.PermissionPolicy
  [Expand]DevExpress.Persistent.Validation
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

PersistenceValidationController Class

Validates persistent objects when they are saved or deleted in the UI.

Namespace:DevExpress.ExpressApp.Validation
Assembly:DevExpress.ExpressApp.Validation.v17.1.dll

Expanded Syntax

Expanded Remarks

This Controller is activated in root Detail Views and List Views. To provide validation in the particular Context, the Controller subscribes to the IObjectSpace.Committing and IObjectSpace.CustomDeleteObjects event of the current View's Object Space. The table below contains peculiarities of this process.

Context DefaultContexts.Save DefaultContexts.Delete
Event IObjectSpace.Committing IObjectSpace.CustomDeleteObjects
Validated objects The View.CurrentObject, its aggregated objects and other modified in the current Object Space objects are validated. The objects marked for deletion and their aggregated objects are validated.
Handling In the event handler, all validation rules from the RuleSet.RegisterRules collection associated with the Save validation context are checked, and if at least one rule is broken, the Controller cancels execution of the Save Action and raises a validation exception. In the event handler, all validation rules associated with the Delete validation context are checked, and if at least one rule is broken, the Controller cancels execution of the Delete Action and raises a validation exception.
Validation result
  • Validation failed
    No modified and created objects are saved in the database and the current Object Space and all editors have the same state as before committing.
  • Validation passed
    All modified and created objects are saved in the database.
  • Validation failed
    No objects are deleted from the database and no changes are made in the current View and in the current Object Space.
  • Validation passed
    All objects that are marked for deletion are deleted from the current Object Space and will be deleted from the database after the IObjectSpace.CommitChanges method is executed. By default, this method is executed immediately, but if the DeleteObjectsViewController.AutoCommit property is set to false, the CommitChanges method will be executed later when you click Save or SaveAndClose, for example.

The PersistenceValidationController exposes several events that allow you to customize the default validation process.

EventDescription
ContextValidatingHandle this event to modify the collection of objects which will be validated in the current context.
CustomGetAggregatedObjectsToValidateHandle this event to manually specify aggregated objects to be validated.
NeedToValidateObjectHandle this event to exclude particular objects from validation.

The example below demonstrates how you can use the PersistenceValidationController class and the events described in the table above.

For example, adjust the rules for the Person class, which has an aggregated collection of Address objects and a non-aggregated collection of the Story objects. The code snippet below demonstrates these classes decorated with the RuleCriteriaAttribute.

The following rules are formed for validating the objects above.

  • The Address objects do not need to be validated if their City property is set to Tokyo.
  • Aggregated objects need to be validated if the root object is modified.
  • When the current object is Person, it is validated only if this object was modified. Aggregated objects modifications are ignored.
  • If the Person object is modified, all objects from its Stories collection are checked.

Create a new controller which uses the PersistenceValidationController controller to validate objects depending on the rules above. The NeedToValidateObject event is handled here to specify whether the objects with a particular property value need to be validated or not. The CustomGetAggregatedObjectsToValidate event is used to modify a collection of aggregated objects to validate. The ContextValidating event allows organizing a collection of all objects to be validated in the particular context.

Expanded Inheritance Hierarchy

System.Object
    System.MarshalByRefObject
       System.ComponentModel.Component
          Controller
             ViewController
                PersistenceValidationController

Expanded See Also

How would you rate this topic?​​​​​​​