Telerik blogs

A very common concern in Telerik OpenAccess ORM (as well as almost every other ORM product on the market) is how the names of the classes that represent your database tables are formed. Basically the mechanism for generating such names follows a simple pattern – the database table name is in plural form and the class name in the model is in single form. However, in the past OpenAccess covered a really small area of all the rules present for singularizing a given word. As of Q3 2009 this is not an issue anymore. We have implemented a simple, yet powerful inflector tool that would do all the singularizing for you. This inflector comes with some predefined rules that specify the way names should be formed as well as some irregular and uncountable words. Being “armed” with so many functions allows the inflector to be really adequate in almost all cases. In case of some more specific scenarios where the inflector is not able to provide the correct word we have introduced an XML file where you can define exceptions for the already predefined rules. This file is located under [installationfolder]\Telerik\OpenAccess ORM\sdk\IDEIntegrations\templates\PCClassGeneration\NamingRules.xml.

Using this file you will be able to define two types of exceptions to the basic rules:

  • Custom rules for specific words
  • Reserved words

The custom rule for each word is an XML entry that represents the single and the plural form of a word. For example if we would like to create a rule for the word virus we would need to create an entry like this:

<stemming plural="viruses" singular="virus"/>

Note that the above rule will be applied for all words that end on virus. For example the rule will be applied for DeadlyViruses but it won’t be applied for VirusesThatKill.

The other possibility would be to define a reserved word. The reserved word is a word that is always mapped to the same result regardless of the action (pluralization, singularization). To define a reserved word you will need to add the following entry:

<reserved word=”Name”properMapping=”myName”/>

Note that the above will be applied only if there is an exact match. For example, the word FriendlyName won’t be matched by this rule.

By using those approaches, you will be able to successfully customize or even completely alter the way that OpenAccess generates your class names.

Last but not least, all the generated words are validated against the Microsoft CODE DOM provider which ensures that they are valid for the given language.


Comments are disabled in preview mode.