Archive

Event rules are triggered upon a lifecycle event of a CodeFluent Entities concept allowing the developer to plug himself in the lifecycle (e.g. before saving an entity, or before the validation step) of an entity to extend its behavior. Event rules can be applied on the following three concepts:

On entities,

On properties,

On methods.

The third one (On Methods) contains three event rule types:

OnAddParameters

OnAfter

OnBefore

Until today the Count and Delete methods were not supported by Method event rules. This post is meant to let you know that as of today Delete and Count methods can be used with event rules.

We saw in a previous post that we could integrate your own custom producer to the Modeler by adding a producerDescriptor element to the Custom.config; well the same feature is available to rules as well.

To add them to the modeler so you can use them through the “Add Rule Dialog” rather than in XML, you need to locate the Custom Configuration File. Open Visual Studio and in Tools > Options… > CodeFluent Entities, and select the advanced view using the advanced button at the top of the property grid. As you can see, there’s a property named “Custom Configuration File Path” which points to a Custom.config file.

By default, this file doesn’t exist, get to the pointed directory and create this Custom.config file with the following content:

In this previous post we created a few web forms which allowed us to list, create, edit, delete contacts using a CodeFluent Entities generated SQL Server database and object model.

Today, we’re going to use CodeFluent Entities to add a validation rule on our contact’s first name and last name, to ensure no invalid characters can be typed-in (we’re going to use a String validation rule to do that).

By the way, CodeFluent Entities provides the following out-of-the-box validation rules:

Regular Expression (specify a regular expression to validate an input),

Custom (define your own!)

Since rules are implemented in the Business Object Model, those validation rules will be available in all upper layers, so all your clients whatever they are (ASP.NET, Winforms, WPF, Silverlight, etc.) will benefit from them.

More information on Rules in CodeFluent Entities available here: Documentation.

Check-out the video to see how to declare it in your model and use it in your ASP.NET:

Note: In the video, we’re not using the graphic interface but editing the XML directly.