-
Notifications
You must be signed in to change notification settings - Fork 0
Good Practices
The following article is a compilation of advice from common mistakes that we see on SoftFluent CodeModeler projects.
A common mistake is to add platform specific code in models. Although, it definitely can happen that for some reason there are no other way than to actually write a SQL query for instance, this should be limited as much as possible since the more platform specific code there is in the model, the more your model is coupled with technology which results in less flexible applications.
Therefore, use as much platform independent concepts as possible: for instance, always prefer writing standard CMQL methods to unchecked or raw methods.
Bad Practice:
delete(int RoleId) where Role.Id=@RoleId
Of course, this method is valid, however writing so implies that the identifier of the Role entity is of the integer type, so if you change its type, or change its key into a composite key, you’ll have to write this method over. However, using entities directly instead of their keys solves this issue:
Good Practice:
delete(Role) where Role=@Role
Both CMQL queries will produce the same final SQL statement, however the second version is way more flexible.
Do not repeat declaring entity type name in method name. For instance, in the SecurityItemRights entity below, replace:
by:
There is no need to write raw SQL to test if a value exists in a method. This can be done in CMQL thanks to the Exists operator. Check-out the CMQL Operators article for more information.
A "TOP" statement can be added to final generated stored procedures by setting the “Maximum Count” attribute on source CMQL methods. There's no need to write raw SQL to do so:
A common mistake is to write raw SQL to access a value contained in a Many-To-Many relation property, when in fact it can be done without any extra work in CMQL.
For instance, in the following example a User can have several Roles, and one Role can be assigned to several Users. Nevertheless, if you want to load all users with a role name containing a specific token, instead of writing a raw SQL query, you could do it in a single line CMQL query, such as:
- Introduction
- Architect Guide
- Concepts
- Using Visual Studio
- Overview
- Creating a CodeModeler Project
- Visual Environment
- Project Hierarchy
- Design Surface
- Customizing Design Surfaces
- Ribbon Bar
- Property Grid
- Member Format Expressions
- Model Grid
- Method Editor
- View Editor
- Instance Editor and Grid
- Resources Editor
- Inferred Model Viewer
- Building
- Project Physical Layout
- Source Control Support
- Generating
- Aspect Oriented Design (AOD)
- Developer Guide
- The Business Object Model (BOM)
- CodeModeler Query Language (CMQL)
- Starting Guide - Tutorial
- Upgrade From CFE