Validating a database

04 Jul

Using the above example, I could bind a Text Box to Selected User.

User Name, and it would automatically show an Error Template if the string was too long, however it wouldn’t show an error template if the User Name already exists.

In the above example, the Users View Model might look like this: (); public void Add Validation Delegate(Validation Delegate func) public void Remove Validation Delegate(Validation Delegate func) #endregion // Validation Delegate #region IData Error Info for binding errors string IData Error Info.

Error string IData Error Info.this[string property Name] public string Get Validation Error(string property Name) #endregion // IData Error Info for binding errors #endregion // IData Error Info & Validation Members The idea is that your Models should only contain raw data, therefore they should only validate raw data.

After some thought, I decided to add a Validation Delegate to my Models to solve this problem.

This is a delegate which View Models can use to add Business Logic Validation to its Models.

You can validate data by handling the Cell Validating event, which is raised by the Data Grid View when the current cell changes.

Business Logic, which includes business rules, should be validated in the View Model, and by exposing a Validation Delegate that they can subscribe to, this can happen.

Next, I have a really simple database table that can be used for lookups. I accept a “Typed Xml Document”, yank out the underlying Xml Document, grab a pointer to the “Validation Errors” record, and append a new node containing whatever error message was defined within the BRE. Before building my rules in the BRE, I wanted to establish a friendly vocabulary for my XML nodes, database columns and helper functions.

Based on providing a “study” and “product” value (which comes in via the inbound XML), I want to be able to figure out which “investigator” to add to the message. NET class to perform a few functions that the BRE doesn’t provide for me out of the box. So, I defined a new vocabulary and created definitions for all the “get”, “set” and “function” operations that my rules required.

When you display data entry functionality to users, you frequently have to validate the data entered into your form.

The Data Grid View class provides a convenient way to perform validation before data is committed to the data store.