Home > .NET Domain Model > Business Data Validation

Business Data Validation


Using CodeFluent Entities you can set business validation rules on properties in your model, which the Business Object Model (BOM) Producer will into actual C# code. Out-of-box validation rules include:

  • String validation (e.g. non null, non empty, etc.),
  • Comparison validation (e.g. value x compared to value y with a specific operator) ,
  • Regular Expression validation (e.g. check regexp matches),
  • Object validation (e.g. object is non null),
  • Url validation (e.g. is a valid url, on a specific port or scheme if desired),
  • Email validation (e.g. is a valid email, from a valid domain if desired),
  • Luhn code validation (e.g. is a valid Luhn Code such as a social security number or credit card number),
  • or your own custom validation rule.

For instance, let’s add an email validation rule on a property:

image

The BOM producer will automatically generate a validation method including the following code:

protected virtual void ValidateMember(CultureInfo culture, string memberName, IList<CodeFluentValidationException> results)
{
     if (((memberName == "Email") || (memberName == null)))
     {
          ValueValidator.Validate(this, culture, "Email", results, Contact.EmailValidator0, this.Email);
     }
}

Since the validation logic is implemented in the BOM, all upper layers will automatically benefit from it. Furthermore, graphically speaking, validation capabilities are supported in all generated user interfaces we support. Here’s an example of a SharePoint web part generated automatically by our Microsoft SharePoint Producer which displays a validation error message automatically upon a validation error:

image

Note: By the way, the message you’re seeing is the default one, but keep in mind that all validation error messages can be localized globally or specifically per property.

Finally, the generated code also implements automatically two handy interfaces: the standard IDataErrorInfo one, and the custom ICodeFluentSummaryValidator which allows developers to have all validation exceptions in a single list.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s