Skip to main content
A newer version of this page is available. .

RuleObjectExistsAttribute.MessageTemplateMustExist Property

Specifies the text to be written in the Validation Error window when the current rule is broken.

Namespace: DevExpress.Persistent.Validation

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

Declaration

public string MessageTemplateMustExist { get; set; }

Property Value

Type Description
String

A string value representing the text to be written to the Validation Error window when a rule is broken.

Remarks

When defining a RuleObjectExists rule via the RuleObjectExistsAttribute in code or in the Model Editor, you may need to invert it (see RuleBaseAttribute.InvertResult), so that it is broken when objects that satisfy the specified criteria are found. In this instance, you should write a custom definition to be displayed in the Vaidation Error window for the broken rule. To do this, set the CustomMessageTemplate property. However, the list of the found objects will not be displayed. To display them, specify the MessageTemplateMustExist property instead of the CustomMessageTemplate property. The following code demonstrates this:

[RuleObjectExists("ComplexValidationSettingsObject_RuleObjectExists", DefaultContexts.Save,
   "FirstName = '@FirstName' AND LastName = '@LastName'", MessageTemplateMustExist = 
   "Objects with the same combination of the" +
   "'FirstName' and 'LastName' properties must not exist.", 
   InvertResult = true, SkipNullOrEmptyValues = true)]
public class ComplexValidationSettingsObject : BaseObject {
   //...
}

This code is taken from the FeatureCenter demo that illustrates all the capabilities of the Validation module. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\FeatureCenter folder, by default.

To customize the format that is used to list the found objects in the Validation Error window, use the RuleObjectExistsAttribute.FoundObjectMessageFormat and RuleObjectExistsAttribute.FoundObjectMessagesSeparator properties.

There is a set of format items you can use in message templates. For instance, when using the {TargetObject} format item, the validated object will be inserted at runtime. For details, refer to the RuleBaseAttribute.CustomMessageTemplate property description.

See Also