Archive

Posts Tagged ‘Rules’

Count and Delete methods now supported by Event Rules

November 20, 2012 Leave a comment

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:

  1. On entities,
  2. On properties,
  3. 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.

More information on Event rules in the documentation.

Cheers,

Thibault NESTOR

Rules in CodeFluent Entities (Video)

June 21, 2011 Leave a comment

Following the same idea as exposed in the Methods post, CodeFluent Entities allows developers to specify rules in their models. Different types of rules are available to us:

  • Event rules: triggered upon a lifecycle event of a CodeFluent Entities concept (entity creation, save, delete, read record, property set, etc.),
  • Validation rules to validate data inputs,
  • Transaction rules: lets you wrap a method in a transaction,
  • Implementation rules: specify that an entity implements a particular interface for instance,
  • Authorization rules: define permissions in your object model,
  • Custom rules: implement your own custom rules.

Here are two videos illustrating different types of rules.

The first one illustrates how to add a Validation rule on a property:

How to define Validation rules

The second one shows how to add an Event rule and how they can be used to extend the generated code by adding your own custom logic:

How to extend the generated code using event rules

Integrating your Custom Rule to the Modeler

March 10, 2011 1 comment

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.

As you know, you can define rules in your model such as:

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:

<codeFluent.Modeler> 
    <ruleDescriptors> 
          <ruleDescriptor name="MyCustomRule" displayName="My Custom Rule" targets="Entity, Project" typeName="CodeFluent.Modeler.Design.Rules.UnresolvedRuleDescriptor, CodeFluent.Modeler"> 
              <propertyDescriptors category="Global"> 
                  <propertyDescriptor name="MyValue" defaultValue="" options="Mandatory" description="A Mandatory value" category="MyCategory" /> 
                  <propertyDescriptor name="MyBoolValue" typeName="System.Boolean" defaultValue="true" /> 
              </propertyDescriptors> 
          </ruleDescriptor> 
      </ruleDescriptors> 
</codeFluent.Modeler>

Launch Visual Studio, open a model and click “Add Rule” on the project or an entity:

CustomRule

Ta-da! Our custom rule was added to the modeler!

Modeler Overview

February 4, 2011 Leave a comment

Wondering how it goes to develop an application using CodeFluent Entities?

Check-out this video! Using the Modeler in Visual Studio 2010, you’ll see how to:

· Define entities,

· Define properties,

· Define enumerations,

· Collaborate,

· View the inferred Meta-Model (CodeFluent Entities is not template based generation!),

· Generate,

· Define instances,

· Generate continuously,

· Define methods,

· Add validation rules,

· Extend the generated code,

· Use the XML view,

· WPF Smart Client Producer,

· SharePoint Web Parts Producer,

· A custom ASP.NET MVC web site,

· Create a model from an existing application (Northwind).

 

Data Validation in an ASP.NET Web Form

January 20, 2011 1 comment

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:

  • Compare with another value (<, >, =, <=, >=)
  • String (null, empty, invalid characters),
  • Email (valid email, valid domains),
  • Url (valid url, absolute or relative, valid host name types, valid host names, valid ports, valid schemes)
  • Luhn (valid Luhn code, allow whitespaces),
  • Object (is object, allows null or empty),
  • 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.

See you soon for more!

The R&D Team

Follow

Get every new post delivered to your Inbox.

Join 52 other followers